Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

RFC: Idiom for named read-write arguments (aliases) instead of using $_[0] etc

by LanX (Canon)
on Sep 01, 2012 at 21:39 UTC ( #991197=perlmeditation: print w/ replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    sub swap {
      my ($a, $b) = \(@_);
    ...
    print "($x,$y)";    #> (42,666)
    swap($x,$y);
    print "($x,$y)";    #> (666,42)
    
  2. or download this
    sub swap {
      my $a = \shift;
    ...
      ( $$a, $$b ) = ( $$b, $$a );  
    }
    
  3. or download this
    sub swap { 
       ($_[0], $_[1] ) = ( $_[1], $_[0] ); 
    }
    

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://991197]
Approved by Corion
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (14)
As of 2015-07-28 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls