Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: printing last 100 keys from hash

by guha (Priest)
on May 21, 2004 at 10:49 UTC ( [id://355234]=note: print w/replies, xml ) Need Help??


in reply to printing last 100 keys from hash

I can see two issues with your example.

1. As DrHyde says the order of a hash is not defined the way one expects. You will have do an explicit sort, depending of the value of your keys, the default sort may suffice or you may have to create an appropriate sort function.

2. Your use of the Range operator is not correct. The right argument must be larger than the left.

This should lead to something along the lines of

for (grep defined($_), (sort keys %db)[-100 .. -1]) {
HTH

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (3)
As of 2024-04-25 21:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found