Re: cant process string in system()



On 2/27/06, Brent Clark <bclark@xxxxxxxxxxxxxxx> 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 be
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


Relevant Pages

  • Re: Case-insensitive matching on compiled regex?
    ... You should have read that in perlop, ... qr/STRING/imosx ... STRING is interpolated the same way as ... interpolation is done. ...
    (comp.lang.perl.misc)
  • Re: Case-insensitive matching on compiled regex?
    ... You should have read that in perlop, ... STRING is interpolated the same way as ... interpolation is done. ... i'm a dope. ...
    (comp.lang.perl.misc)
  • Re: what is the "=-" operator
    ... perlop more or less verbatim. ... negation operators may be omitted. ... If the operand is an identifier, a string consisting of a minus sign ...
    (comp.lang.perl.misc)
  • Re: Perl - Bit Manipulation
    ... >> its left to be interpreted as a string. ... >> So I filed a bug-report about perlop. ... yet it provides the hash key '1'. ... And we know '01' isn't a Perl identifier so we no longer expect it to be ...
    (perl.beginners)
  • Re: Perl - Bit Manipulation
    ... Randal L. Schwartz schreef: ... And AFAICS that isn't true: ... So I filed a bug-report about perlop. ... Evaluates to a list of the words extracted out of STRING, ...
    (perl.beginners)