我想解析文件中的一些信息。在該文件中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