Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Performance Trap - Opening/Closing Files Inside a Loop

by Ven'Tatsu (Deacon)
on Dec 10, 2004 at 16:47 UTC ( #413905=note: print w/replies, xml ) Need Help??


in reply to Re^3: Performance Trap - Opening/Closing Files Inside a Loop
in thread Performance Trap - Opening/Closing Files Inside a Loop

Variable declaration with a statment modifier can have stange effects, usally a lexical not getting cleared as expected, due to my having both runtime and compile time effects, the test only blocks the runtime effect of resetting the variable. This can be used for some interesting obfu but should be avoided in serious code IMO.
# if EXPR is false $foo will still have the last set value for this sc +ope's (but not other scope's) $foo my $foo if EXPR; #same here if EXPR is false the first time it's tested on this pass. my $bar while EXPR;
It's rather common to stick a declaration inside the test of a (BLOCK) loop, often seen with input loops, or looping over both keys and values of a hash at the same time.
while (my $foo = <$fh>) { #do something } while (my ($key, $value) = each %hash) { #do other things }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2022-08-17 01:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?