develooper Front page | perl.perl5.porters | Postings from November 2011

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

Thread Previous | Thread Next
From:
wolfsage
Date:
November 22, 2011 07:08
Subject:
Re: defined(@arr), defined (%hash)
Message ID:
CAJ0K8bjyiRKKx7uNFRjHfGH1hMkNL9QBTOiwppQRwP47_XB-9w@mail.gmail.com
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 = ()...

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");

-- 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