Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

perl -pae '$_ = "$F[1]\n";' test23.txt

works on my Linux machine but not on my Windows machine.

whereas:
perl -pae "$_ = "$F[1]\n";" test23.txt

works on my windows machine but not on my linux machine.

The only difference between these two commands are the single quotes/double quotes used to enclose the command specified by the -e flag. Can anybody tell me why the two perl systems differ in this respect when one of Perls strongpoints is deemed to be its portability?
Thanks,
Sean

Edited by Chady -- added code tags.

Replies are listed 'Best First'.
Re: Perl Syntax Variation Between Linux/Windows when -e flag is used!
by davis (Vicar) on Mar 26, 2004 at 15:35 UTC

    It's got nothing to do with perl.
    It's the different quoting methods used by your shells (probably bash on Linux, and cmd.exe on Windows). If you put the code in a file, and did something like perl foo.pl test23.txt, it would work equally well on both OS's


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
Re: Perl Syntax Variation Between Linux/Windows when -e flag is used!
by Happy-the-monk (Canon) on Mar 26, 2004 at 15:35 UTC

    It's not Perl's fault!

    The reason being that the particular shells on those OSes require a different syntax ("" or '') for foreign stuff to be protected from their own command interface.

    Sören

Re: Perl Syntax Variation Between Linux/Windows when -e flag is used!
by MADuran (Beadle) on Mar 26, 2004 at 15:41 UTC
    My understanding is commandline quoting is shell dependent. So it is how the CMD.EXE or COMMAND.COM is excepting quotes. On Win32 the double quotes is the only way to tie a space seperated parameter together. Because of the issues with single quotes on WIN32 command line I usually use the quote-like operators on the command line in win32.
    Example  perl -pae "$_ = qq|$F1\n|;" test23.txt

    I have seen this issue is mentioned in the Camel 3rd edition as an issue (pages 489-491 of Programming Perl 3rd Ed).
    HTH

    MADuran
    Who needs a spiffy sig
      Thanks to all involved -Happy-The-Monk, MADuran and davis---for clearing this up for me.
      So its not perls fault--i stand corrected. Also I will use the qq in future.
      Sean