I'm currently debugging a subroutine that takes exactly 61 arguments. After spending a few days working out how it's called ("... so here argument 37 is null, but over here argument 37 is "Phooey", and argument 53 is null, except when ..."), I'm wondering why more people don't call subroutines with a single hash as the argument.
Is it dreadfully expensive, in terms of memory usage? It's more verbose, true, but it means that:
Am I missing something? I can see this would be pointless if there are only a few arguments to be passed, but it looks like it could improve my code legibility no end.
What do monks think? I know that hashes as arguments has come up a few times before (like here, for one), but no-one seems to have expressed whether it's a good idea, a bad idea, or JAWTDI.
For novices who aren't sure what I'm not about, try this:
&foo( bork => 'glorp', ningi => 'fertangg!', flarp => undef ); exit; sub foo(%) { my %args_of = @_; foreach ( keys(%args_of) ) { print "The argument '", $_, "' was set to: ", defined( $args_of{$_} ) ? $args_of{$_} : '(undefined)', "\n"; } 1; }
which outputs:
The argument 'bork' was set to: glorp
The argument 'ningi' was set to: fertangg!
The argument 'flarp' was set to: (undefined)
--
2003-06-05 edit ybic: <readmore> tags, monasterialized link to related prior thread ( like so [id://120181] ) to prevent logout for monks with cookie not from "www".
In reply to passing subroutine args as a hash: why not? by Willard B. Trophy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |