in reply to Determine first element in foreach
my ( $first, @list ) = @{my_list}; treat_1( $first ); treat_others( $_ ) for @list;
If $my_list can be destroyed, it can be made shorter.
treat_1( shift @$my_list ); treat_others( $_ ) for @$my_list;
If it cannot be destroyed, it can still be done without the temporary variables:
treat_1( $my_list->[0] ); treat_others( $my_list->[$_] ) for ( 1 .. $#{$my_list} );
Update: Added a couple of more different implementations.
--MidLifeXis
|
---|