develooper Front page | perl.perl5.porters | Postings from February 2013

Re: [perl #116981] 'our sub' segfaults perl if the sub did not compile

Thread Previous | Thread Next
Peter Martini
February 28, 2013 08:38
Re: [perl #116981] 'our sub' segfaults perl if the sub did not compile
Message ID:
On Thu, Feb 28, 2013 at 2:15 AM, Jesse Luehrs <> wrote:
> On Wed, Feb 27, 2013 at 11:05:42PM -0800, Peter Martini via RT wrote:
>> Digging into this, I also realize:
>> perl -Mfeature=lexical_subs -e 'my sub foo { foo(1);} foo;'
>> Undefined subroutine &main::foo called at -e line 1.
>> Is that intentional?
> It is consistent with how lexical variables work elsewhere - new
> lexicals are not available to be used until after the statement they are
> declared in is finished:
>   $ perl -E'use strict; say(my $foo = 1, $foo)'
>   Global symbol "$foo" requires explicit package name at -e line 1.
>   Execution of -e aborted due to compilation errors.
> On the other hand, it's not consistent with how non-lexical subs work.
> This is probably one of the cases where a decision had to be made about
> what to be consistent with, and I think in most cases, the choice was to
> be consistent with the equivalent long-hand version, so
> 'my $foo = sub { $foo->(1) }' in this case (which also doesn't work).
> It's possibly useful to note that __SUB__ will work in both of these
> cases.
> That said, I do agree that it's confusing, and an argument could
> possibly be made for doing it the other way, although I don't know what
> the implications for the implementation would be.
> -doy

Ah. point taken, and you're precisely right, I was thinking in terms
of subs instead of lexicals. And it is documented, so sorry for the

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About