慢慢来
分类: Python/Ruby
2012-11-07 15:58:16
#!/usr/bin/perl for($j=0;$j<4;$j++) { print "$ARGV[$j] \n"; } |
[macg@localhost perltest]$ ./tip.pl 36 gg test a 36 $ARGV[0]==36 gg test a |
#!/usr/bin/perl for($j=0;$j<4;$j++) { print "$ARGV[$j] "; } print "\n"; $tmp=shift(@ARGV); print "$tmp\n"; for($j=0;$j<4;$j++) { print "$ARGV[$j] "; } print "\n"; |
[macg@localhost perltest]$ ./tip.pl 36 gg test a 36 gg test a 36 gg test a 重新打印参数列(变短了) |
#!/usr/bin/perl @arraytest="hello "test" world"; 如果字符串内也有双引号,比如HTTP语句,就会形成双引号套双引号的问题 foreach (@arraytest) { print $_,"\n"; } |
[macg@localhost perltest]$ ./tip.pl Bareword found where operator expected at ./tip.pl line 2, near ""hello "test" (Missing operator before test?) 出错 |
#!/usr/bin/perl @arraytest=qq(hello "test" world); foreach (@arraytest) { print $_,"\n"; } |
[macg@localhost perltest]$ ./tip.pl hello "test" world |
#!/usr/bin/perl @arraytest=("aaa","bbb","123"); foreach (@arraytest) { print $_,"\n"; } | #!/usr/bin/perl @arraytest=qw(aaa bbb 123); foreach (@arraytest) { print $_,"\n"; } |
[macg@localhost perltest]$ ./tip.pl aaa bbb 123 | [macg@localhost erltest]$ ./tip.pl aaa bbb 123 |
[macg@localhost perltest]$ vi tip.pl #!/usr/bin/perl @arraytest=("aaa","bbb","123"); foreach $tmp (@arraytest) { print $tmp,"\n"; } |
[macg@localhost perltest]$ ./tip.pl aaa bbb 123 |
[macg@localhost perltest]$ vi tip.pl #!/usr/bin/perl @arraytest=("aaa","bbb","123"); foreach (@arraytest) { print $_,"\n"; } |
[macg@localhost perltest]$ ./tip.pl aaa bbb 123 |
@arraytest=("aaa","bbb","123"); foreach (@arraytest) { print;} |
[macg@localhost perltest]$ ./tip.pl aaabbb123[macg@localhost perltest]$ |
rmdir($tmp[0]) || die "$!"; |
[macg@localhost perltest]$ ./tip.pl testdir 0 Directory not empty at ./tip.pl line 13, <> line 2. |
print $$ ,"\n"; |
[macg@localhost perltest]$ ./tip.pl 2861 |
#!/usr/bin/perl print $0 ,"\n"; |
[macg@localhost perltest]$ ./tip.pl ./tip.pl |