in reply to Re^3: Aren't there code refs as well as function refs?
in thread Aren't there code refs as well as function refs?
here a 2 variants with aliases instead of passing references
# https://perlmonks.org/?node_id=11150731 use strict; use warnings; my ($x, $y) = qw{X Y}; print "BEFORE:\n"; print "\$x[$x] \$y[$y]\n"; mod_callers_vars1($x, $y); print "AFTER1:\n"; print "\$x[$x] \$y[$y]\n"; mod_callers_vars2($x, $y); print "AFTER2:\n"; print "\$x[$x] \$y[$y]\n"; sub mod_callers_vars1 { @_[0,1] = ('A','B'); return; } sub mod_callers_vars2 { my ($x_ref, $y_ref) = \(@_); $$x_ref = 'C'; $$y_ref = 'D'; return; }
--->
BEFORE: $x[X] $y[Y] AFTER1: $x[A] $y[B] AFTER2: $x[C] $y[D]
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
|
|---|