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

Re: [perl #56150] return return

Thread Previous | Thread Next
Ronald J Kimball
June 20, 2008 09:06
Re: [perl #56150] return return
Message ID:
On Fri, Jun 20, 2008 at 08:04:27AM -0700, Nicholas Clark wrote:

> $ ./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).

It seems to me that there's lots of useless code that nonetheless isn't a
syntax error...  :)

Perhaps that construct could generate a warning.  Personally, I wouldn't
expect it to be a syntax error.

(Note that return can be usefully used as an expression:
my $foo = $bar ? return : 'baz';
Odd, but it works.)


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