>>>>> "SC" == Stuart Cook <scook0@gmail.com> writes: SC> The think I don't like about `foo( *$bar )` is that it's not clear SC> whether you're splatting a pair, or a hash, or an array, or a complete SC> argument-list object. This is probably fine for quick-'n'-dirty code, SC> but I'd like to encourage a more explicit style: but perl will know the type of the value in $bar and expand/splat it accordingly. SC> my $pair = a=>'b'; SC> foo( *%$pair ); # view the pair as a 1-elem hash, and splat that the % there isn't a hash. perl can see the single pair and deal with that. the way to make this more readable is to use better variable names. $pair here is fine and *$pair would mean to splat it into the named arguments. SC> my $href = \%hash; # or just %hash SC> foo( *%$href ); # view the hashref as a hash, and splat that same as above. perl sees the href and will just DWIM. SC> sub returns_a_hash { ... } SC> foo( *%{returns_a_hash} ); # call the sub, view the result as a SC> hash, and splat that isn't that what hash() is for? what is returns_a_hash really returning, a list or a hash ref because you can't return a hash (or can you this week? :). SC> my $aref = \@array; # or just @array SC> foo( *@$aref ); # view the arrayref as an array, and splat that again, autoderef would work fine here. i don't see the benefit of the extra @. SC> sub returns_an_array { ... } SC> foo( *@{returns_an_array} ); # call the sub, view the result as a SC> hash, and splat that where is the hash? wouldn't you want %{} in your system? and %{} derefs a hash and doesn't convert a list to a hash. that is what hash() does. uri -- Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com --Perl Consulting, Stem Development, Systems Architecture, Design and Coding- Search or Offer Perl Jobs ---------------------------- http://jobs.perl.orgThread Previous | Thread Next