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

Re: [perl #56150] return return

Thread Previous | Thread Next
From:
Ronald J Kimball
Date:
June 20, 2008 09:06
Subject:
Re: [perl #56150] return return
Message ID:
20080620160631.GB3180@penkwe.pair.com
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.)

Ronald



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