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

Re: [perl #56150] return return

Thread Previous | Thread Next
Rafael Garcia-Suarez
June 20, 2008 09:29
Re: [perl #56150] return return
Message ID:
2008/6/20 via RT Nicholas Clark <>:
> $ ./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)}'

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

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