in reply to Returning and using a glob from a sub.
Trying to find out why revealed that it works pretty well from a source file.
script:
use strict; use warnings; use Data::Dump; $\="\n"; our $x='X'; our $y='Y'; our (@x,@y,@z); # return lvalue glob sub lg :lvalue { *x }; print '--- make $x alias of $y' ; lg=\$y; dd \*x; print '$x= ',"'$x'"; $y='YY'; print '$x= ',"'$x'"; print '--- make *x alias of *z' ; lg=*z; dd \*x; our $z='Z'; print '$x= ',"'$x'"; @z=qw(Z ZZ ZZZ); print '@x= ',"qw/@x/";
output:
--- make $x alias of $y do { my $a = \*main::x; *{$a} = \"Y"; *{$a} = []; $a; } $x= 'Y' $x= 'YY' --- make *x alias of *z do { my $a = \*main::z; *{$a} = []; $a; } $x= 'Z' @x= qw/Z ZZ ZZZ/
output from Data::Dump seems correct... globs are just confusing
changed dd *a to dd \*a to make output of Data::Dump less confusing
²) not a bug, just a problem with my debugger settings!
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
|
|---|