The think I don't like about `foo( *$bar )` is that it's not clear
whether you're splatting a pair, or a hash, or an array, or a complete
argument-list object. This is probably fine for quick-'n'-dirty code,
but I'd like to encourage a more explicit style:
my %hash = (a=>'b', c=>'d');
foo( *%hash ); # splat a hash as named arguments
# => foo( a=>'b', c=>'d' );
my $pair = a=>'b';
foo( *%$pair ); # view the pair as a 1-elem hash, and splat that
my $href = \%hash; # or just %hash
foo( *%$href ); # view the hashref as a hash, and splat that
sub returns_a_hash { ... }
foo( *%{returns_a_hash} ); # call the sub, view the result as a
hash, and splat that
my @array = (1, 2, 3);
foo( [EMAIL PROTECTED] ); # splat an array as positional arguments
# => foo( 1, 2, 3 );
my $aref = [EMAIL PROTECTED]; # or just @array
foo( [EMAIL PROTECTED] ); # view the arrayref as an array, and splat that
sub returns_an_array { ... }
foo( [EMAIL PROTECTED] ); # call the sub, view the result as a
hash, and splat that
In this style, the splat character (*) is always next to a sigil (% or
@) telling you exactly how the arguments are being substituted (named
or positional).
I'm also a little wary of giving parens the power to change pair
behaviour, but the rules are simple enough that I can probably get
over it. The other proposal, IIRC, was to have `named()` and `pair()`
special-forms for forcing the desired behaviour; these would only be
valid in argument lists.
Stuart