Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
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 meditating upon the Monastery: (7)
As of 2014-08-01 23:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (51 votes), past polls