in reply to Passing by Named Parameter
sub mysub { %params = %{ +shift }; my %known_options = ( 'this' => 1, 'that' => 2 ); PARSE: foreach my $param ( keys %params ) { exists $known_options{$param} && do { #something; next PARSE; }; die "Usage: I only know how to 'this' and 'that'\n"; } # Rest of sub here... }
Just One Way To Do It.
The values assigned to keys in %known_options are just numeric for this example, but could be coderefs, subrefs, flag values, or whatever you want.
Update: Better late than never, fixed %params = %{ +shift }; syntax.
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
I've never seen =that= before!
by John M. Dlugosz (Monsignor) on Jan 27, 2004 at 15:41 UTC | |
by Abigail-II (Bishop) on Jan 27, 2004 at 15:47 UTC |