>>>>> "SC" == Stuart Cook <[EMAIL PROTECTED]> 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 = [EMAIL PROTECTED];  # or just @array
  SC>   foo( [EMAIL PROTECTED] );  # 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( [EMAIL PROTECTED] );  # 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  ------  [EMAIL PROTECTED]  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

Reply via email to