Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^3: HTML::LinkExtor weirdness (scoping closures nested named subs)

by Anonymous Monk
on Nov 07, 2013 at 00:27 UTC ( #1061507=note: print w/replies, xml ) Need Help??


in reply to Re^2: HTML::LinkExtor weirdness (scoping closures nested named subs)
in thread HTML::LinkExtor weirdness

This is why you don't nest named subs, the closure becomes "static"

perl -E " sub f{ my %g; sub g{say \%g; } g(); say \%g; \%g } say f(),$/ for 1 .. 4;"

perl -E ' sub f{ my %g; sub g{say \%g; } g(); say \%g; \%g } say f(),$/ for 1 .. 4; '

HASH(0xabd9c4) HASH(0xabd9c4) HASH(0xabd9c4) HASH(0xabd9c4) HASH(0x3f9b6c) HASH(0x3f9b6c) HASH(0xabd9c4) HASH(0x3f9b8c) HASH(0x3f9b8c) HASH(0xabd9c4) HASH(0x3f9b6c) HASH(0x3f9b6c)

By making the nested subroutine a variable (also known as an anonymous sub), the closure is dynamic

$ perl -lE " sub f{ my %g; my $g = sub {say \%g; $g{1}++}; $g->(); say \%g; \%g } say f(),$/ for 1 .. 4;"

HASH(0xabd9d4) HASH(0xabd9d4) HASH(0xabd9d4) HASH(0x3f9b1c) HASH(0x3f9b1c) HASH(0x3f9b1c) HASH(0x99b374) HASH(0x99b374) HASH(0x99b374) HASH(0x99b344) HASH(0x99b344) HASH(0x99b344)
  • Comment on Re^3: HTML::LinkExtor weirdness (scoping closures nested named subs)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1061507]
help
Chatterbox?
[tye]: that is what getlogin() certainly *used* to do. I don't believe that is what it certainly should do.
[davido]: /var/run/utmp is 664 i think.
[tye]: Note that my "man getlogin" says that it uses stdin when it should use /dev/tty (calling a glibc bug). But that does not appear to be the case when I test it. But maybe Perl's getlogin() is not using glibc's getlogin().
[oiskuu]: well, run a strace and see what the getlogin does for you.... As I said. SELinux probably has those security labels. But not regular linux.
[tye]: for example, read https://unix. stackexchange.com/ questions/146138/ loginuid-should-be -allowed-to-change -or-not-mutable-or -not
[tye]: I'm not using SELinux and it certainly appears to disagree with you. shrug
[tye]: Since you brought up /proc, oiskuu, I didn't see you respond to my suggestion of 'loginuid'. Does your /proc not have such?

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2017-06-23 19:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (554 votes). Check out past polls.