The following code works only on mac, but not on windows7.
perl -e "print @ARGV" aaa^bbb
On Mac (perl 5.10, da开发者_StackOverflow社区rwin) it prints out as expected: aaa^bbb
On Windows 7,32bit (ActivePerl 5.12) it prints out: aaabbb
The "^" character is thrown out of @ARGV. This character is part of a filename that I'm using the script with, so I need to be able to read it from @ARGV.
I tried using "aaa\^bbb" but it just prints out "aaa\bbb".
It's not ActivePerl that's discarding the ^
character, it's the Windows command prompt:
C:\>echo aaa^bbb
aaabbb
You need to quote the argument:
C:\>perl -e "print @ARGV" "aaa^bbb"
aaa^bbb
Or you can escape it with a second caret:
C:\>perl -e "print @ARGV" aaa^^bbb
aaa^bbb
The caret ^
is an escape character, similar to \
in Unix shells.
It doesn't work on Strawberry Perl, either. However, you can get around this by passing the argument into quotes:
perl -e "print @ARGV" "aaa^bbb"
Using Strawberry Perl on Windows 7, the output is
aaa^bbb
精彩评论