Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re: How to pass by reference

by bbfu (Curate)
on Jul 31, 2006 at 07:15 UTC ( #564696=note: print w/ replies, xml ) Need Help??

in reply to How to pass by reference

There's a couple of options. You can use the aliasing behavior of @_, or you can pass an actual reference.

sub func_alias { $_[0] = 5; } sub func_ref { my $ref = shift; $$ref = 5; } my $x; func_alias($x); print "x = $x\n"; my $y; func_ref(\$y); print "y = $y\n";

The latter is probably better, as it is less likely to cause surprise the caller (ie, it's more explicit that you're potentially modifying the function parameter).

Black flowers blossom
Fearless on my breath

Comment on Re: How to pass by reference
Download Code

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2015-11-26 00:51 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (695 votes), past polls