in reply to passing subroutine args as a hash: why not?
i've found named parameters extremely helpful. in fact, perl 5.008 has made them even better, thanks to locked hashes (the pseudo-hash replacement.) enter Hash::Util...
#/usr/bin/perl use strict; use warnings; $|++; require 5.008; use Hash::Util; my %hash= ( one => undef, two => 2, three => 'abc', ); Hash::Util::lock_keys( %hash ); print $_,$/ for keys %hash; ## causes runtime error $hash{add}= 'yes';
now i can both provide default values in my modules or subroutines, and automatically handle errors when extraneous parameters are passed. also, specific keys can be locked, so you can create a hash of constants.
that allows me to delete all my code like
defined $hash{$key} or die $key, ' is not valid';
because Hash::Util::lock_hash handles it for me! aah, Hash::Util.
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: passing subroutine args as a hash: why not?
by Willard B. Trophy (Hermit) on Jun 05, 2003 at 19:02 UTC |