in reply to Re^2: Sub hash param by reference
in thread Sub hash param by reference
It's a whole lot easier and more subtle than you might expect. Perl actually passes parameters as aliases in @_ so we can:
use warnings; use strict; my %hash_rec = (id => "001"); doSub2($hash_rec{id2}); print "main: id2 = $hash_rec{id2}\n"; sub doSub2 { $_[0] = "Hello alias"; }
Prints:
main: id2 = Hello alias
We don't usually take advantage of that trick because without due care it's likely to lead to hard to maintain code.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Sub hash param by reference
by hankcoder (Scribe) on Jul 08, 2016 at 04:54 UTC | |
by Athanasius (Archbishop) on Jul 10, 2016 at 08:44 UTC | |
by hankcoder (Scribe) on Jul 10, 2016 at 12:46 UTC |