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.
The question, is there a more efficient way to do this? I don't like having to use the $Arrayindex++; method to achieve this.my @SampleArray = ("one","two","three" ); my $Arrayindex = 0; foreach my $ArrayItem ( @SampleArray ){ print $ArrayItem , ' is at location ' , $Arrayindex , ' in the arr +ay' , "\n"; $Arrayindex++; }
Back to
Seekers of Perl Wisdom