我想解析文件中的一些信息。在该文件中perl中的模式匹配
信息:
Rita_bike_house_Sha9
Rita_bike_house
我想有一个像DIS
$a = Rita_bike_house and $b = Sha9,
$a = Rita_bike_house and $b = "original"
为了输出得到,我用下面的代码:
$name = @_; # This @_ has all the information from the file that I have shown above.
#For matching pattern Rita_bike_house_Sha9
($a, $b) = $name =~ /\w\d+/;
if ($a ne "" and $b ne "") { return ($a,$b) }
# this statement doesnot work at all as its first condition
# before the end is not satisified.
是有什么方法可以在$a
中存储“Rita_bike_house”,在$b
中存储“Sha9”?我认为我的正则表达式缺少某些东西。你能提出什么建议吗?
'$ name = @ _'是一种代码味道。您可能的意思是['($ name)= @ _'](http://stackoverflow.com/q/10031455/168657)。 – mob
'\ w'也匹配'_'(下划线),所以你需要更精确的匹配规则。 – jm666
对不起。是的,它是($ name)= @_; – user2498830