Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Re: While on hashes doesn't work?

by merlyn (Sage)
on Feb 04, 2002 at 23:38 UTC ( [id://143318]=note: print w/replies, xml ) Need Help??


in reply to Re: While on hashes doesn't work?
in thread While on hashes doesn't work?

while (($_) = sort keys %data){ print "while: $data{$_}\n"; delete $data{$_}; }
This is a pretty expensive loop. You'd be much better doing:
while (my ($k, $v) = each %data) { print "key is $k, value is $v\n"; }
Without those parens around $_, I would expect it to try to pass '5' into the block (which it would do) if you took away the sort function, but it doesn't do that. I suppose that might qualify as an insignificant bug.
No, sort in a scalar context always returns undef. Maybe someday, it'll return something useful. But not yet. No bug, except in perhaps your understanding. {grin}

-- Randal L. Schwartz, Perl hacker

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (1)
As of 2024-04-24 13:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found