爲什麼此代碼打印51而不是26?我試圖提取「價值」。 即我想要(粗體一個):<選項值=「安達曼&尼科巴」 >安達曼&尼科巴< /選項>Perl m操作員問題
作爲每個定義米與列表上下文g操作者應在括號返回模式?
my $firstpage=<<'EOF';
<option value="Andaman & Nicobar">Andaman & Nicobar</option>
<option value="Andhra Pradesh">Andhra Pradesh</option>
<option value="Assam">Assam</option>
<option value="Bihar">Bihar</option>
<option value="Calcutta Telecom District">Calcutta Telecom District</option>
<option value="Chennai Telecom District">Chennai Telecom District</option>
<option value="Chhattisgarh">Chhattisgarh</option>
<option value="Gujarat">Gujarat</option>
<option value="Haryana">Haryana</option>
<option value="Himachal Pradesh">Himachal Pradesh</option>
<option value="Jammu & Kashmir">Jammu & Kashmir</option>
<option value="Jharkhand">Jharkhand</option>
<option value="Karnataka">Karnataka</option>
<option value="Kerala">Kerala</option>
<option value="Madhya Pradesh">Madhya Pradesh</option>
<option value="Maharashtra">Maharashtra</option>
<option value="North East I">North East I</option>
<option value="North East II">North East II</option>
<option value="Orissa">Orissa</option>
<option value="Punjab">Punjab</option>
<option value="Rajasthan">Rajasthan</option>
<option value="Tamilnadu">Tamilnadu</option>
<option value="UP East">UP East</option>
<option value="UP West">UP West</option>
<option value="Uttaranchal">Uttaranchal</option>
<option value="West Bengal">West Bengal</option>
EOF
my @cities=$firstpage=~m{(?<=")([^"]*)(?=")}gs;
print scalar @cities;
輕微的觀察,這並不樣子有效的HTML,你應該逃避和到& – IanNorton 2011-03-30 18:37:14
假如您打印'@ cities'而不是'scalar @ cities',你會早一點得到你的答案。如果*摘要*信息拋出您,則不要僅打印摘要信息。 – Axeman 2011-03-30 23:15:50