cant process string in system()
am 27.02.2006 13:47:11 von Brent Clark
Hey all
Im trying to run the following
system ('fetchmail -f '.$fetchmailconf.' -a -k -r \"'.$folderitem.'\"');
What im getting is:
Processing INBOX.Astro Computers :
for bclark@Computers": <- this is wrong, must be INBOX.Astro Computers
My code is as so:
foreach my $folderitem (@folderlist){
chomp $folderitem;
$newfolderitem = $folderitem;
$newfolderitem =~ s/\s/_/g;
print "Processing $folderitem : \n";
system ('fetchmail -f '.$fetchmailconf.' -a -k -r \"'.$folderitem.'\"');
}
exit;
Basically what happening is, when I pass the variable to system() the spaces are not escaped etc, and therefore fetchmail
only processing only half the string.
If anyone knows how I can achieve in processing the string as is, would be most grateful
Kind Regards
Brent Clark
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
Re: cant process string in system()
am 27.02.2006 15:16:22 von Chas Owens
------=_Part_3157_1035623.1141049782217
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
On 2/27/06, Brent Clark wrote:
snip
> Basically what happening is, when I pass the variable to system() the
spaces are not escaped etc, and therefore fetchmail
> only processing only half the string.
>
> If anyone knows how I can achieve in processing the string as is, would b=
e
most grateful
snip
There are two methods of calling system that should solve your problem:
use the system shell and surround the arguments with quotes
system(qq(fetchmail -f "$fetchmailconf" -a -k -r "$folderitem"));
and avoid using the shell altogether
system('fetchmail', '-f', $fetchmailconf, '-a', '-k', '-r', $folderitem);
It looks like you were trying to do the first an got confused by the
behaviour of single quote strings.
The string ' -a -k -r \"' is stored as the literal [-][a][ ][-][k][ ]-[r][
][\]["]. This is becuase single quote strings do not handle
interpolation. Here is the relevant section of the perlop* documentation:
Customary Generic Meaning Interpolates
'' q{} Literal no
"" qq{} Literal yes
For constructs that do interpolation, variables beginning with "$"
or "@" are interpolated, as are the following sequences. Within a
transliteration, the first ten of these sequences may be used.
\t tab (HT, TAB)
\n newline (NL)
\r return (CR)
\f form feed (FF)
\b backspace (BS)
\a alarm (bell) (BEL)
\e escape (ESC)
\033 octal char (ESC)
\x1b hex char (ESC)
\c[ control char
\l lowercase next char
\u uppercase next char
\L lowercase till \E
\U uppercase till \E
\E end case modification
\Q quote non-word characters till \E
* you can read the rest of the perlop documentation by typing "perldoc
perlop" or "man perlop" on your command line or by going to
http://perldoc.perl.org/perlop.html
------=_Part_3157_1035623.1141049782217--