Which is the best implementation(in terms of speed and memory usage) for iterating through a Perl array? Is there any better way? (@Array
need not be retained).
Implementation 1
foreach (@Array)
{
SubRoutine($_);
}
Implementation 2
while($Element=shift(@Array))
{
SubRoutine($Element);
}
Implementation 3
while(scalar(@Array) !=0)
{
$Element=shift(@Array);
SubRoutine($Element);
}
Implementation 4
for my $i (0 .. $#Array)
{
SubRoutine($Array[$i]);
}
Implementation 5
map { SubRoutine($_) } @Array ;
转载于:https://stackoverflow.com/questions/10487316/best-way-to-iterate-through-a-perl-array