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

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

Thread Previous | Thread Next
From:
wolfsage
Date:
January 25, 2012 10:08
Subject:
Re: defined(@arr), defined (%hash)
Message ID:
CAJ0K8biuFTFA32AcdWQtR1P7ECrbX9EuFyk_Yam0iP1cWHuSQA@mail.gmail.com
On Wed, Jan 25, 2012 at 12:34 PM, Nicholas Clark <nick@ccl4.org> wrote:

> On Sun, Jan 22, 2012 at 12:31:20PM -0800, Father Chrysostomos wrote:
> > Matthew Horsfall wrote:
>
> > > I've had a few others look at it and most gave that same response.
> It's not
> > > pretty, but it successfully traverses the op tree, and doesn't break
> any
> > > tests :)
>
> You'd be surprised by how many obscure things one can change that turn out
> not to have tests.
>

I wish I was surprised.


>
> > > I think it's good to go in until proven otherwise.
> >
> > I understand the patch, and can see, even without checking, that it
> > bypasses the pushmark on the lhs of aassign and looks at the next op,
> > which is safe even in the case of an empty list, as that consists of a
> > stub op.
>
> That's what I didn't know, and so couldn't say with confidence.
> That there's always going to be something there, so it will never be a
> NULL pointer.
>
> > I don't think the patch is appropriate, as it's defined(@array) and
> > defined(%hash) that are being deprecated, not defined(@array=...).  An
> > aggregate on the lhs of a list assignment is not touched by the list
> > assignment's parent op, so it's unrelated.  Also (without actually trying
> > it) the patch will warn for defined((@a,$a) = stuff), but not for
> > defined(($a,@a) = stuff).
>
> 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:
>

Hmm, okay. I misunderstood what was getting evaluated during an OP_ASSIGN
inside of defined(). Thanks everyone for explaining. :)

-- Matthew Horsfall (alh)

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