in reply to Passing hashes as arguments to a sub?

I'm not familiar with Params::Validate that was mentioned; however, there is a simple example of being strict with hash keys in "Perl Medic." It goes something like this:
sub name { # this puts the passed list into a hash my %arg = @_; # this transfers values to variables and removes the keys my ($key1, $key2) = delete @arg{qw(key1 key2)}; # this determines if any keys are leftover croak 'Illegal arguments' if %arg; }

Replies are listed 'Best First'.
Re^2: Passing hashes as arguments to a sub?
by leocharre (Priest) on Nov 28, 2005 at 19:29 UTC
    #make hash my %junk = ( one=>'123123', two=>'dsf4f3' ) # send reference &printvals(\%junk); sub printvals { my $junk=$_[0]; #dereference these guys print $$junk{one} . $$junk{two}; }