想要從具有多個數字的變量中精確地匹配數字,該數字由與egrep.below相似的管道符號分隔,這是我嘗試的代碼。perl匹配與egrep類似的變量中的多個數字
#!/usr/bin/perl
my $searchnum = $ARGV[0];
my $num = "148|1|0|256";
print $num;
if ($searchnum =~ /$num/)
{
print "found";
}
else
{
print "not-found";
}
預期O/P
perl number_match.pl 1
found
perl number_match.pl 1432
not-found
您的代碼與給定的一組數字的工作,並沒有得到你的闕,你想使它通用? 。 – 2013-02-13 10:16:26
@ashu當我運行perl number_match 1432其返回發現,我應該找不到,我想匹配整個數字說例子1應該匹配1不是148因爲1是可用的148 – 2013-02-13 10:25:25