Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Isn't Perl5 ready for C<my sub>?

by friedo (Prior)
on Sep 07, 2005 at 16:48 UTC ( #489932=note: print w/replies, xml ) Need Help??


in reply to Re: Isn't Perl5 ready for C<my sub>?
in thread Isn't Perl5 ready for C<my sub>?

(With all the caveats of local and symboltable hacking, of course.)

The main problem I see with this approach is that it doesn't behave the way we would expect a true lexical sub too. For example, I would expect the following to work:

sub foo { my sub bar { print "42\n"; } return sub { bar() }; } my $s = foo(); $s->();

Of course that won't work with the local trick since you can't have a lexical closure over a locally modified symbol table (as far as I know.) But it would work fine if you used my $bar = sub { print "42\n" }.

I suppose a source filter to convert my sub bar { } to my $bar = sub { } would do the trick, but then you'd have to scan the rest of the block to change bar to $bar->(). Sounds like a real PITA.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2022-01-21 15:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:












    Results (59 votes). Check out past polls.

    Notices?