develooper Front page | perl.perl5.porters | Postings from June 2008

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
Rafael Garcia-Suarez
Date:
June 20, 2008 09:29
Subject:
Re: [perl #56150] return return
Message ID:
b77c1dce0806200929o4d248171q5d2ab9c95ed60588@mail.gmail.com
2008/6/20 via RT Nicholas Clark <perlbug-followup@perl.org>:
>
> $ ./perl -Ilib -e 'sub foo {return return}'
> $
>
> How come this isn't a syntax error? It can't possibly do anything useful.
> (Actually, it seems that anything can be passed the return value of return.
> C<print return> works just fine).

return is technically parsed as a list operator (LSTOP).
That enables using it in compound expressions.

Note that this syntax works also for other control flow statements :

$ perl -wle '$i=3;while(1){print($i--||last)}'
3
2
1

I don't really see a reason to change it.

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About