in reply to Re^3: Local for lexicals
in thread Local for lexicals
Seems you just want a complicated way of not writing $_[0] in the sub. That can be done of course. But why would you? And what has this to do with localizing a lexical, which you were asking about in your earlier posts? If you're passing in the parameter to the sub, there's no need to localize anything, is there?In order:
(formatted, I think, specifically to be faithful to my original attempt), or even more briefly as just:my $f = sub {my $x = shift; sub {$x ** 2}->()};
then it certainly works. I would just like to avoid the slight extra verbiage and write insteadmy $f = sub { my $x = shift; $x**2 }
as syntactic sugar (well, for some definition of ‘sugar’) for the same thing.my $f = lambda $x => sub { $x**2 }
|
|---|