Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re^2: shift vs @_

by Cop
on Dec 23, 2007 at 19:48 UTC ( #658801=note: print w/replies, xml ) Need Help??

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

What wrong with my $x, $y = @_? Putting perl specifics away (not worried about the syntax like whether you should say my (a,b)). More and more languages are support this kind of de-group operation.

Replies are listed 'Best First'.
Re^3: shift vs @_
by blazar (Canon) on Dec 25, 2007 at 15:24 UTC

    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://658801]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2018-05-25 22:28 GMT
Find Nodes?
    Voting Booth?