亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: perl -n -e 已驗(yàn)證命令行方式正確 但在perl中執(zhí)行報錯 [打印本頁]

作者: enna56    時間: 2015-01-06 17:38
標(biāo)題: perl -n -e 已驗(yàn)證命令行方式正確 但在perl中執(zhí)行報錯
有這樣一條去重復(fù)行的命令,我在命令行輸入,無報錯且結(jié)果正確,

perl -n -e 'if (/^\s*$/){print;next};if (exists($hash{$_})) {next} else {$hash{$_}=1;print}' /tmp/digdig/apache/tosfstat1tmp > /tmp/digdig/apache/11111.txt

可是當(dāng)我要把它放在perl里面的時候,

#!/usr/bin/perl

use strict;
use Time::Local;
use warnings;

perl -n -e 'if (/^\s*$/){print;next};if (exists($hash{$_})) {next} else {$hash{$_}=1;print}' /tmp/digdig/apache/tosfstat1tmp > /tmp/digdig/apache/11111.txt

會報錯如下:
-bash-4.1$ ./del_conflict.pl
Bareword found where operator expected at ./del_conflict.pl line 28, near "11111.txt"
        (Missing operator before txt?)
syntax error at ./del_conflict.pl line 28, near "n -e "
Execution of ./del_conflict.pl aborted due to compilation errors.
-bash-4.1$

不知這是要設(shè)置什么嘛

多謝~~
作者: zhlong8    時間: 2015-01-06 19:24
你這么寫應(yīng)該叫 shell 腳本,而不是 Perl 腳本
作者: lokchungk    時間: 2015-01-06 23:18
本帖最后由 lokchungk 于 2015-01-06 23:19 編輯

You should do something like this
  1. #!/usr/bin/perl -n
  2. use Time::Local;
  3. if (/^\s*$/){print;next};if (exists($hash{$_})) {next} else {$hash{$_}=1;print}
復(fù)制代碼

作者: enna56    時間: 2015-01-07 09:11
回復(fù) 2# zhlong8

嗯嗯  是滴  請問要怎么把這種shell中的命令  改在可以在perl里面執(zhí)行呢?


   
作者: enna56    時間: 2015-01-07 09:40
回復(fù) 3# lokchungk


是要這樣嗎

my $tosfstat1tmp = $localdir."tosfstat1tmp";
open (FILEHANDLE_1tmp,$tosfstat1tmp) or die "cannot open logFile: $tosfstat1tmp";

while(<FILEHANDLE_1tmp>){
my %hash;
if (/^\s*$/){print;next};if (exists($hash{$_})) {next} else {$hash{$_}=1;print}
}
close (FILEHANDLE_1tmp);


這里的print要怎么可以重定向到另一文件里面哪?我上面這樣做的話,只是打印出$tosfstat1tmp的內(nèi)容,也沒有去重復(fù)行

   
作者: lokchungk    時間: 2015-01-07 11:51
  1. >cat test.pl        
  2. #!/usr/bin/perl -ln
  3. print && (/^\s*$/ ? () : $h{$_}++ ) if ! exists $h{$_}
  4. >cat test.txt
  5. abc
  6. def

  7. abc
  8. def
  9. ghi
  10. ghi
  11. jkl
  12. >perl test.pl < test.txt
  13. abc
  14. def

  15. ghi
  16. jkl
復(fù)制代碼

作者: quanpai    時間: 2015-01-08 12:49
用 system 或者 ``
  1. #!/usr/bin/perl

  2. my $output = `ls -lrt`;
  3. print $output;

  4. system("ls -lrt > output.txt");
復(fù)制代碼

作者: enna56    時間: 2015-01-08 13:19
回復(fù) 7# quanpai


好的好的  多謝偶~~


   




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2