sub blah { my ($foo, $bar, $baz) = @_; for my $arg (qw( foo bar baz )) { croak("$arg missing/undefined") if !defined(shift); } ... }
I know that I must be missing something here (UPDATE: yup!), but why not just
or even something like the List::MoreUtils-flavouredsub blah { my ( $foo, $bar, $baz ); for my $arg ( ( $foo, $bar, $baz ) = @_ ) { croak "You forgot something" unless defined $arg; } do_something; }
That is, why have the for loop run over the argument list ‘indirectly’ when it's right there to be had?sub blah { croak "You forgot something" unless all { defined } ( my ( $foo, $ +bar, $baz ) = @_ ); do_something; }
UPDATE: Indeed, I missed the entirety of the author's point, which was precisely that he wanted more than what his code snippet already did—namely, to detect which, if any, of the relevant variables was already defined.
In reply to Re^2: Can you find the name of a variable?
by JadeNB
in thread Can you find the name of a variable?
by pileofrogs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |