develooper Front page | perl.perl6.language | Postings from April 2003

* vs **

Thread Next
From:
Paul
Date:
April 22, 2003 14:51
Subject:
* vs **
Message ID:
20030422215146.432.qmail@web41204.mail.yahoo.com
S6:
===
<quote>
The unary prefix operator * flattens its operand (which allows the
elements of an array to be used as an argument list). The * operator
also causes its operand -- and any subsequent arguments in the argument
list -- to be evaluated in list context.

   sub foo($x, $y, $z) {...}    # expects three scalars
   @onetothree = 1..3;          # array stores three scalars

   foo(1,2,3);                  # okay:  three args found
   foo(@onetothree);            # error: only one arg
   foo(*@onetothree);           # okay: (array) flattened to three args

The * operator flattens lazily -- the array is only flattened if
flattening is actually required within the subroutine. To flatten
before the list is even passed into the subroutine, use the unary
prefix ** operator:

   foo(**@onetothree);          # array flattened before &foo called

</quote>
===

So is ** actually a seperately implemented operator, or is that the *
op working on the return from the * op, like the way Larry suggested
the ref-of-ref operator, \\ ? :)


__________________________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo
http://search.yahoo.com

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About