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

Re^6: Benifits of using hash rather than number of variables?

by duelafn (Vicar)
on Jul 21, 2011 at 15:27 UTC ( #915902=note: print w/replies, xml ) Need Help??

in reply to Re^5: Benifits of using hash rather than number of variables?
in thread Benifits of using hash rather than number of variables?

Note: Updated my previous reply with various proposed solutions.

Indeed, the initial implementation (lock_keys %params, qw/ key1 key2 key3 /;) is equivalent to your solution there. Though, my reading of the OP was that they wanted to use hashes rather than set a bunch of variables like that and lock_keys offers no less protection than the originally proposed Tie::Hash::Vivify.

My personal use of lock_keys is restricted to command line option parsing and some cases where it is "easy" to set up on hashes that may be passed around or used a lot (for example, log file parsing as described in The value of declarations). If I were looking for a complete solution for subroutine arguments I would most likely reach for Params::Validate or similar since once you move beyond lock_keys %params, qw/ key1 key2 key3 /;, the added coding effort for proper validation (vs just verifying key names) isn't much.

Good Day,

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://915902]
[LanX]: Jeez ... the new location for GPW so remote that hotels are cheaper than AirBnB oO
[LanX]: ... and I can get faster to the Dutch PW or French PW ...
LanX ...(by train from Frankfurt)

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2018-03-19 11:50 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (239 votes). Check out past polls.