in reply to Determine first element in foreach
Can anyone tell me how i can obtain the first element?
To answer the question exactly as asked you can shift off the first element:
my @array = qw/one two three/; my $x = shift @array;
That will remove the first element from the array leaving 'two','three'. If you don't want to alter the list you can directly access the first element:
my @array = qw/one two three/; my $x = $array[0];
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Determine first element in foreach
by Anonymous Monk on Aug 05, 2014 at 08:17 UTC |