Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re^3: shift vs @_

by blazar (Canon)
on Dec 25, 2007 at 15:24 UTC ( #658965=note: print w/replies, xml ) Need Help??

in reply to Re^2: shift vs @_
in thread shift vs @_

I personally believe that for once Cop's question is legitimate, but one cannot put "Perl specifics away" since this is Perl: while avoiding a pair of parentheses may represent an occasional advantage -I for one try to avoid them all the time, if possible- in this particular case wouldn't square at all with Perl's whole syntax and semantics. Anyway, as this very thread and tons of similar ones show, Perl's current argument passing mechanism is both fascinating for the far reaching consequences it gets out of an extreme simplicity on the one hand, and awkward on the other one. This is why after some initial period of being skeptical I now cherish Perl 6's message passing. For very simple stuff I can still rely on @_ and not worry at all. Suppose I want to write a sub that will take a list (of strings) and concat it after making all lowercase every element out of two starting with the first, and all uppercase the other ones; then I'd write it like this:

pugs> sub foo { [~] map -> $a, $b { lc $a, uc $b }, @_ }; pugs> say foo <FoO bAr BaZ>; fooBARbaz

But if I were to write a sub that would take two integers and return the product of integer numbers comprised between them, then I would write:

pugs> sub prod (int $n, int $m) { [*] $n..$m }; pugs> say prod 3, 6; 360
If you can't understand the incipit, then please check the IPB Campaign.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://658965]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2018-04-21 18:35 GMT
Find Nodes?
    Voting Booth?