sub getIndex {
my ($array, $value)[EMAIL PROTECTED];
my $x=0;
foreach (@{$array}) { $_ eq $value ? return $x : $x++; } #only works
if array has unique items and is slow, but could be easy if it fits
your problem
#personally, I don't recommend this, but maybe it's what
you were thinking of?
}
#!usr/bin/perl
my @arr = qw/a b c d e a/; #last element will list as zero!
for(@arr)
{
my $num=getIndex([EMAIL PROTECTED], $_);
print "The No.$num element is $_\n";
}
On Feb 27, 2006, at 11:07 PM, <[EMAIL PROTECTED]>
<[EMAIL PROTECTED]> wrote:
hi, perlers,
Is there a simple way to get the current index of an array in loop
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";
}
-----------------------------------------------
Life is a different teacher...
It doesn't teach lessons, and then keep exams...
It keeps the exams first and then teaches the lessons.