http://www.perlmonks.org?node_id=1020128

default_user has asked for the wisdom of the Perl Monks concerning the following question:

In the following example I create an additional variable to keep track where I am in the array.
my @SampleArray = ("one","two","three" ); my $Arrayindex = 0; foreach my $ArrayItem ( @SampleArray ){ print $ArrayItem , ' is at location ' , $Arrayindex , ' in the arr +ay' , "\n"; $Arrayindex++; }
The question, is there a more efficient way to do this? I don't like having to use the $Arrayindex++; method to achieve this.