Re: the way to get current index of an array
- From: mlists@xxxxxxxxxxxxxxx (JupiterHost.Net)
- Date: Tue, 28 Feb 2006 07:54:06 -0600
zhao_bingfeng@xxxxxxxxxxxxx wrote:
hi, perlers,
Howdy,
Is there a simple way to get the current index of an array in loop
yes
statement? the procondition is you cannot get this information from
array element. For example
#!usr/bin/perl
my @arr = qw/a b c d e/;
for(@arr)
{
print "The No.?? element is $_\n";
}
for my $idx (0 .. $#arr) {
print "The no $idx element is $arr{$_}\n";
}
my $idx = 0;
for my $item(@arr) {
print "The no $idx element is $item\n";
$idx++;
}
There are other more magical ways but those will probably be best for you :)
The first way not only has less code but is faster.
HTH :)
.
- References:
- the way to get current index of an array
- From: Zhao Bingfeng
- the way to get current index of an array
- Prev by Date: Is there a GNU-like "mkdir -p" method in Perl?
- Next by Date: separate input
- Previous by thread: Re: the way to get current index of an array
- Next by thread: Re: the way to get current index of an array
- Index(es):
Relevant Pages
|
|