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

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

Thread Previous | Thread Next
From:
Nicholas Clark
Date:
January 3, 2012 02:35
Subject:
Re: defined(@arr), defined (%hash)
Message ID:
20120103103510.GN9069@plum.flirble.org
On Tue, Nov 22, 2011 at 10:08:19AM -0500, Matthew Horsfall (alh) wrote:
> On Tue, Nov 22, 2011 at 8:23 AM, Ricardo Signes
> <perl.p5p@rjbs.manxome.org>wrote:
> 
> > ...but:
> >
> >  perl -E'use warnings; defined(our @a)'
> >  (no deprecation)
> >
> > (package hashes are still deprecated)
> >
> >
> Actually, it gets weirder:
> 
>   perl -we 'print defined(%hash = ())'
>   defined(@array) is deprecated at -e line 1.
>           (Maybe you should just omit the defined()?)
> 
> OP_RV2AV is explicitly ignored, but I don't quite follow the reason, and
> OP_AASSIGN incorrectly catches %hash = () as @array = ()...

I don't think that your explanation is quite correct. But I'm not sure what
the correct mental model is. In that:

$ ./perl -e 'sub foo {}; print defined(() = foo);'
defined(@array) is deprecated at -e line 1.
        (Maybe you should just omit the defined()?)

It's conflating lists with arrays, and then using the "array" message when
the thing in question is a list.

Does the warning message need a bit more checking on AASSIGN, to determine
whether what is being assigned to is an array or a list?

> OP *
> Perl_ck_defined(pTHX_ OP *o)            /* 19990527 MJD */
> {
>     PERL_ARGS_ASSERT_CK_DEFINED;
> 
>     if ((o->op_flags & OPf_KIDS)) {
>         switch (cUNOPo->op_first->op_type) {
>         case OP_RV2AV:
>             /* This is needed for
>                if (defined %stash::)
>                to work.   Do not break Tk.
>                */
>             break;                      /* Globals via GV can be undef */
>         case OP_PADAV:
>         case OP_AASSIGN:                /* Is this a good idea? */
>             Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
>                            "defined(@array) is deprecated");
>             Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
>                            "\t(Maybe you should just omit the
> defined()?)\n");

Nicholas Clark

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