Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: Why is "any" slow in this case?

by LanX (Saint)
on Aug 04, 2025 at 21:28 UTC ( [id://11165957]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Why is "any" slow in this case?
in thread Why is "any" slow in this case?

Yeah I see your point now.

Seems like Perl is playing safe if a lexpad is required for the closure, even if the closed over lexical variable doesn't change, like here:

$ perl use v5.14; my @subs; sub dosomething :prototype(&) { push @subs, $_[0]; } my $x; for (1..2) { dosomething { $x+1 } } for (1..2) { my $x; dosomething { $_+1 } } say for @subs; __END__ CODE(0x64405f0de700) CODE(0x64405f10b340) CODE(0x64405f118bb0) CODE(0x64405f118bb0)

BTW: Clever move to push the code-refs to @subs and keeping them alive instead of printing them out.

Like this you are avoiding that Perl tries to reuse a freed ref again! IOW if we see the same ref again we are sure teh sub wasn't generated again.

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2026-03-08 23:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.