Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: How to pass by reference

by GhodMode (Pilgrim)
on Jul 31, 2006 at 07:20 UTC ( [id://564697]=note: print w/replies, xml ) Need Help??


in reply to How to pass by reference

Just put a backslash in front of the dollar-sign when you pass the variable to the function.

Don't forget to de-reference the variable inside the function ...

use strict; use warnings; my $x = 10; &function( \$x ); # if I change $x = 5 print $x; # $x = 10 sub function { my $x = $_[0]; $$x = 5; } # End function subroutine

--
-- Ghodmode
Blessed is he who has found his work; let him ask no other blessedness.
-- Thomas Carlyle

Log In?
Username:
Password:

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

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

    No recent polls found