Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Optimization, side-effects and wrong code

by benizi (Hermit)
on Oct 01, 2004 at 18:59 UTC ( [id://395704]=note: print w/replies, xml ) Need Help??


in reply to Re: Optimization, side-effects and wrong code
in thread Optimization, side-effects and wrong code

Your code creates an infinite loop, though, if $self->{$k}->{blahblah} never evaluates to true. (whereas the OP's falls through to "return undef;")

perl -Mstrict -lw my %self; $self{$_}{blahblah} = 0 for qw/1 2 3/; while (my $k = each %self || each %self) { print "testing:$k"; print "true for $k" and last if $self{$k}{blahblah}; } __OUTPUT__ testing:1 testing:3 testing:2 testing:1 testing:3 testing:2 testing:1 ... etc. ...

Replies are listed 'Best First'.
Re^2: Optimization, side-effects and wrong code
by bpphillips (Friar) on Oct 01, 2004 at 19:54 UTC
    agreed, I've added exists which causes it to work correctly (albeit a bit different test than the OP's). Could maybe even add a check to make sure our while loop doesn't run past scalar(keys %$self) but then we're back to using keys again... :-)

Log In?
Username:
Password:

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

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

    No recent polls found