Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Returning and using a glob from a sub. (lvalue sub)

by LanX (Saint)
on Dec 13, 2014 at 15:31 UTC ( [id://1110273]=note: print w/replies, xml ) Need Help??


in reply to Returning and using a glob from a sub.

My first idea was using lvalue subs, but it didn't work in the debugger REPL so I thought this might not work ... ( bug?¹ )

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/

UPDATE

output from Data::Dump seems correct... globs are just confusing

UPDATE

changed dd *a to dd \*a to make output of Data::Dump less confusing

UPDATE

²) not a bug, just a problem with my debugger settings!

Cheers Rolf

(addicted to the Perl Programming Language and ☆☆☆☆ :)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1110273]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-26 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found