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

Re^2: Wrong idioms

by Jenda (Abbot)
on Apr 01, 2013 at 10:42 UTC ( #1026458=note: print w/ replies, xml ) Need Help??


in reply to Re: Wrong idioms
in thread Wrong idioms

If you mess with these variables, it's YOUR duty to put them back in order! The code that changes them and leaves them changed is incorrect, not the code that fails to check and/or reset them.

Jenda
Enoch was right!
Enjoy the last years of Rome.


Comment on Re^2: Wrong idioms
Re^3: Wrong idioms
by moritz (Cardinal) on Apr 01, 2013 at 13:14 UTC

    Well, if you mess with your caller's variables, I agree. But if you want to use those variables for your own purposes, you can't help but let the callee also see the changed variables (because you can only localize the, not modify them in a lexical scope).

      Don't call then! All advice you ever hear about changes to these variables says "change them only in the smallest possible scope and do not call anything that might expect them to be set to the normal values".

      Most of the variables are not changed too often so I would not sweat about it. The only one I see changed is $/ and the code usually looks like this:

      my $contents = do {local $/; <HANDLE>;}
      or
      my $contents; { local $/; $contents = <HANDLE>; }

      and the code implementing readline() for handles is the only one I would expect to check the value of $/.

      Jenda
      Enoch was right!
      Enjoy the last years of Rome.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2014-12-28 22:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (183 votes), past polls