develooper Front page | perl.perl5.porters | Postings from January 2012

Re: defined(@arr), defined (%hash)

Thread Previous | Thread Next
From:
Jesse Luehrs
Date:
January 25, 2012 09:40
Subject:
Re: defined(@arr), defined (%hash)
Message ID:
20120125173956.GS23629@tozt.net
On Wed, Jan 25, 2012 at 05:34:59PM +0000, Nicholas Clark wrote:
> without:
> 
> $ ./perl -le 'print defined (($a, %a) = (1,2,3))'
> defined(@array) is deprecated at -e line 1.
>         (Maybe you should just omit the defined()?)
> 1
> $ ./perl -le 'print defined ((%a, $a) = (1,2,3))'
> defined(@array) is deprecated at -e line 1.
>         (Maybe you should just omit the defined()?)
> 1
> 
> with:
> 
> $ ./perl -le 'print defined (($a, %a) = (1,2,3))'
> 1
> $ ./perl -le 'print defined ((%a, $a) = (1,2,3))'
> defined(%hash) is deprecated at -e line 1.
>         (Maybe you should just omit the defined()?)
> 1
> 
> 
> and aaargh, yes, this is starting to seem like the same thing that caused
> bugs with the in-place sort optimisation - that the LHS of a list
> assignment is a list, even if it just looks like an array.
> 
> So you're starting to make me doubt whether the patch is correct, because
> I'm starting to wonder whether the warning is correct for assignment,
> given that what's actually being tested isn't the array (or hash), but
> the list in scalar context:

Yeah, I don't think the patch is correct as-is, but I think it would
still be reasonable to warn in this case (if we can detect that
defined() is what is providing scalar context to the list). It should
have an entirely separate warning though, since it doesn't involve any
actual arrays or hashes.

-doy

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