Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://559061]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2018-06-24 23:19 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.