satchboost has asked for the wisdom of the Perl Monks concerning the following question:

My question is how to make the following code snippet do what I want:
#!/usr/misc/bin/perl5 -w use strict; my $blahblah = 5; my $ref_to_blahblah = \$blahblah; print "$$ref_to_blahblah\n"; fubar($ref_to_blahblah); print "$$ref_to_blahblah\n"; print "$$ref_to_blahblah\n"; sub fubar { $$_[0] = 4; print "$$_[0]\n"; return $_[0]; }
Right now, I'm getting an output of:
5
4
5
What I want is an output of:
5
4
4

Replies are listed 'Best First'.
Re: Modifying outside variables in subroutines
by Fastolfe (Vicar) on Jan 15, 2001 at 19:59 UTC