我在使用下面的代碼在我的Perl腳本中遇到了麻煩,任何建議真的很感激,如何更正語法?如何在Perl腳本中使用Awk?
# If I execute in bash, it's working just fine
bash$ whois google.com | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ($i ~ /[[:alpha:]]@[[:alpha:]]/) { print $i}}}'|head -n1
[email protected]
#-----------------------------------
#but this doesn't work
bash$ ./email.pl google.com
awk: {for (i=1;i<=NF;i++) {if ( ~ /[[:alpha:]]@[[:alpha:]]/) { print }}}
awk: ^syntax error
# Here is my script
bash$ cat email.pl
####\#!/usr/bin/perl
$input = lc shift @ARGV;
$host = $input;
my $email = `whois $host | egrep "\w+([._-]\w)*@\w+([._-]\w)*\.\w{2,4}" |awk ' {for (i=1;i<=NF;i++) {if ($i ~ /[[:alpha:]]@[[:alpha:]]/) { print $i}}}'|head -1`;
print my $email;
bash$
你不應該這樣做,但既然你是,你忘了逃避美元$我。 (下一次,仔細閱讀錯誤消息,你不必問這個問題。) – jrockway 2010-04-19 04:31:07
另外,Perl被創建用來替換grep/sed/awk/...所以你應該只讀'whois'輸出和用Perl解析它。 – 2010-04-19 13:19:22