[pm-h] Binding variables to a reference
Todd Rinaldo
toddr at null.net
Fri Dec 19 21:01:18 PST 2008
This has been driving me crazy, so I have to ask how (and/or if) this
can be done. I have the below program. If you run it, bar prints out.
This exemplifies how you can alter the variables that were passed to a
target subroutine. substr does this but I suspect it's more a result
of magic C code than magic Perl code.
my $foo = 'foo';
bar($foo);
print "$foo\n";
exit;
sub bar {
$_[0] = 'bar';
}
My question, How do I do something like this and get it to print out bar?
my $foo = 'foo';
bar($foo);
print "$foo\n";
exit;
sub bar {
my \$bar = \$_[0];
$bar = 'bar';
}
Todd
More information about the Houston
mailing list