[EMAIL PROTECTED] 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 :)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to