my @someones;
my $xpath = q(//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]/div/div/table/tbody/tr/td/div/div);
for my $i (0,2..20)
{
my @nodes = split qr'/', $xpath;
$nodes[16] .= "[$i]" unless 0 == $i;
#say join '/', @nodes; }
@somenames = join('/',@nodes);
print "\n";
print @somenames ;
}
出力:
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[2]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[3]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[4]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[5]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[6]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[7]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[8]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[9]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[10]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[11]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[12]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[13]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[14]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[15]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[16]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[17]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[18]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[19]/table/tbody/tr/td/div/div
//body[@id='ext-gen3']/div[14]/div[2]/div/div/div/div/div/div/div/div/div/div[2]
/div/div[20]/table/tbody/tr/td/div/div
上記のスニペットを実行すると、20 個の値すべてが 1 つの要素 (つまり、$somenames[0]) に格納されます。しかし、私は各配列要素に格納したいと思いfor i=0,$somenames[0];
for i=2,$somenames[2];
ますfor i=20,$somenames[20]
。どうすればできますか?また、for ループの外側で @somenames を出力すると、20 番目の要素のみが出力されます。配列の各要素に各値を格納する方法は?