B
bernd
Hello folks,
just for confirmation: Is my assumption correct that there is no
"implicit" method to know the current index of an array (means: the
index of the item which is stored in $_ in a foreach-loop for example)
without using an "external" counter variable?
In the following I want to traverse the array @testarr and want to
treat the very first item (but it could be any other arbitrary item as
well) specially. Is there a way of "knowing" the index without using
the explicitly defined variable $count?
$count = 0 ;
foreach ( @testarr ) {
if ( $count == 0 ) { print $_ }
# same code for all items ....
$count++ ;
}
So, can I get rid of $count in some way (by using an implicit
mechanism) or do I have to live with this, IMO, long winded way.
Cheers
Bernd
just for confirmation: Is my assumption correct that there is no
"implicit" method to know the current index of an array (means: the
index of the item which is stored in $_ in a foreach-loop for example)
without using an "external" counter variable?
In the following I want to traverse the array @testarr and want to
treat the very first item (but it could be any other arbitrary item as
well) specially. Is there a way of "knowing" the index without using
the explicitly defined variable $count?
$count = 0 ;
foreach ( @testarr ) {
if ( $count == 0 ) { print $_ }
# same code for all items ....
$count++ ;
}
So, can I get rid of $count in some way (by using an implicit
mechanism) or do I have to live with this, IMO, long winded way.
Cheers
Bernd