Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Determine first element in foreach

by 1s44c (Scribe)
on Aug 04, 2014 at 21:36 UTC ( [id://1096210]=note: print w/replies, xml ) Need Help??


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

    Thanks for the help everyone.

    I will take a look at all the answers and see which solution to implement.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1096210]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-24 19:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found