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

Re: my vs. local subtlety

by esr (Scribe)
on Jul 03, 2006 at 23:35 UTC ( #559061=note: print w/ replies, xml ) Need Help??


in reply to my vs. local subtlety

All of the above comments are valid. But if one: a) has used symbolic refs successfully in other situations; b) does not recognize that symbolic refs find only package variables; c) does not recognize that "my" variables are lexical; d) uses "my" variables frequently in subroutines to avoid the possibility of duplicate variable names; and e) does not recognize that the use of such constructs in a subroutine are "unsafe", "non-robust", "non-versatile", and difficult to maintain; then one can get very frustrated trying to figure out why something isn't working as expected. Some or all of those things applied to me when I wrote that code initially 2-3 years ago. To someone who may be new to Perl, or is not experienced in some of these things, the distinction may boil down to a difference between using "my" and "local" without understanding what is under the covers.

Thanks for your comments. I was not familar with the "map" function mentioned above so I have something new to learn about.

I rewrote the subroutine in the original snippet long ago by passing a list of array refs rather than the letters so the original snippet is only of value to others if this discussion helps them to avoid the pitfalls mentioned.


Comment on Re: my vs. local subtlety

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2014-12-20 10:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (95 votes), past polls