Perl: the Markov chain saw | |
PerlMonks |
these aren't locals, but they seem to act like itby argv (Pilgrim) |
on Mar 11, 2007 at 19:08 UTC ( [id://604242]=perlquestion: print w/replies, xml ) | Need Help?? |
argv has asked for the wisdom of the Perl Monks concerning the following question:
I have some functions that use far too many parameters, and many of the parameters are optional. So as to simplify, I'm converting a lot of them from using many params, so just using one: a hash (whose key/value pairs represent the params that used to be passed).
So, now what I have is a nice elegant API that looks like:
Until I actually convert all the CALLS to the function in the new format, I've written the functions in such a way that it can accept either form by using ref() on the first param and seeing if it's a hash. If so, the function's vars are set to the has key/value pairs. otherwise, the rest of the args are read from @_. All's well and good, and things work properly. However, for one function, there were so many params that I thought I would simplify the above process using a loop as illustrated in the code below. The surprise isn't so much to do with the parameters to the function, but the setting of the values to the local my variables within the function. Can someone explain the scoping going on here that isn't preserving the variables' values outside of the "using args..." block?
Dan Heller http://www.danheller.com
Back to
Seekers of Perl Wisdom
|
|