If you're using 5.10, you can use the new _ (underscore) prototype to create subroutines that magically use either a passed parameter or $_:
sub display_thing (_) { print $_[0] }; $_='Hello 5.10'; display_thing;
Another way would be to just wrap display_thing with your own wrapper that handles the decision between $_ and @_:
my $old_display_thing = \&display_thing; *display_thing = sub { if (@_) { &$old_display_thing(@_) } else { &$old_display_thing($_) }; };
But if you're rewriting or wrapping display_thing (and I see no way around rewriting or wrapping it), why not rewrite or wrap it to accept multiple arguments straight away?
sub display_thing { for (@_) { print "Displaying thing >$_<\n"; }; };
In reply to Re: Is it possible to write a sub that understand default variables ?
by Corion
in thread Is it possible to write a sub that understand default variables ?
by bcarnazzi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |