Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Getting first and last element value of a hash loop

by aaron_baugher (Curate)
on Jun 05, 2015 at 22:01 UTC ( #1129266=note: print w/replies, xml ) Need Help??


in reply to Getting first and last element value of a hash loop

Since a list starts at element 0, the index of the last element in the list is one less than the total number of elements. For instance, if the array @arr contains 5 elements, $arr[4] is the last. Try using [$count-1] as the index to get the last item in your sorted list.

Update: parv's answer is better than mine, see below.

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.

Replies are listed 'Best First'.
Re^2: Getting first and last element value of a hash loop
by parv (Vicar) on Jun 05, 2015 at 22:06 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2020-06-04 18:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you really want to know if there is extraterrestrial life?



    Results (35 votes). Check out past polls.

    Notices?