Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: shift vs @_

by Cop (Initiate)
on Dec 23, 2007 at 19:48 UTC ( [id://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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://658801]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (3)
As of 2024-04-18 23:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found