# merge all the caller's @ISA packages into %isa.
@isa{@{"${prevpack}::ISA"}} = ()
- if(defined @{"${prevpack}::ISA"});
+ if(@{"${prevpack}::ISA"});
# now we crawl up the calling stack and look at all the packages in
# there. For each package, we look to see if it has an @ISA and then
# our caller is a derived class of that package and its calls can also
# be ignored
while (($pack,$file,$line) = caller($i++)) {
- if(defined @{$pack . "::ISA"}) {
+ if(@{$pack . "::ISA"}) {
my @i = @{$pack . "::ISA"};
my %i;
@i{@i} = ();
if ($extra-- > 0) {
%isa = ($pack,1);
@isa{@{$pack . "::ISA"}} = ()
- if(defined @{$pack . "::ISA"});
+ if(@{$pack . "::ISA"});
}
else {
# OK! We've got a candidate package. Time to construct the
}
OP *
+ck_defined(OP *o) /* 19990527 MJD */
+{
+ if (ckWARN(WARN_DEPRECATED)) {
+ switch (cUNOPo->op_first->op_type) {
+ case OP_RV2AV:
+ case OP_PADAV:
+ case OP_AASSIGN: /* Is this a good idea? */
+ warner(WARN_DEPRECATED, "defined(@array) is deprecated (and not really meaningful)");
+ warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
+ break;
+ case OP_RV2HV:
+ case OP_PADHV:
+ warner(WARN_DEPRECATED, "defined(%hash) is deprecated (and not really meaningful)");
+ warner(WARN_DEPRECATED, "(Maybe you should just omit the defined()?)\n");
+ break;
+ default:
+ /* no warning */
+ break;
+ }
+ }
+ return ck_rfun(o);
+}
+
+OP *
ck_rfun(OP *o)
{
OPCODE type = o->op_type;
ck_null, /* schop */
ck_spair, /* chomp */
ck_null, /* schomp */
- ck_rfun, /* defined */
+ ck_defined, /* defined */
ck_lfun, /* undef */
ck_fun, /* study */
ck_lfun, /* pos */
schop scalar chop ck_null stu% S?
chomp safe chop ck_spair mts% L
schomp scalar safe chop ck_null stu% S?
-defined defined operator ck_rfun isu% S?
+defined defined operator ck_defined isu% S?
undef undef operator ck_lfun s% S?
study study ck_fun su% S?
pos match position ck_lfun stu% S?
(W) You used the C<open(FH, "| command")> or C<open(FH, "command |")>
construction, but the command was missing or blank.
+=item defined(@array) is deprecated (and not really meaningful)
+
+(D) defined() is not usually useful on arrays because it checks for an
+undefined I<scalar> value. If you want to see if the array is empty,
+just use C<if (@array) { # not empty }> for example.
+
+=item defined(%hash) is deprecated (and not really meaningful)
+
+(D) defined() is not usually useful on hashes because it checks for an
+undefined I<scalar> value. If you want to see if the hash is empty,
+just use C<if (%hash) { # not empty }> for example.
+
=head1 Obsolete Diagnostics
Todo.
recursion, unless you're writing strange benchmark programs, in which
case it indicates something else.
+=item defined(@array) is deprecated (and not really meaningful)
+
+(D) defined() is not usually useful on arrays because it checks for an
+undefined I<scalar> value. If you want to see if the array is empty,
+just use C<if (@array) { # not empty }> for example.
+
+=item defined(%hash) is deprecated (and not really meaningful)
+
+(D) defined() is not usually useful on hashes because it checks for an
+undefined I<scalar> value. If you want to see if the hash is empty,
+just use C<if (%hash) { # not empty }> for example.
+
=item Delimiter for here document is too long
(F) In a here document construct like C<E<lt>E<lt>FOO>, the label
you're trying to do. At other times, a simple comparison to C<0> or C<""> is
what you want.
-Currently, using C<defined> on an entire array or hash reports whether
-memory for that aggregate has ever been allocated. So an array you set
-to the empty list appears undefined initially, and one that once was full
-and that you then set to the empty list still appears defined. You
-should instead use a simple test for size:
+Use of C<defined> on aggregates (hashes and arrays) is deprecated. It
+used to report whether memory for that aggregate has ever been
+allocated. This behavior may disappear in future versions of Perl.
+You should instead use a simple test for size:
if (@an_array) { print "has array elements\n" }
if (%a_hash) { print "has hash members\n" }
-Using C<undef> on these, however, does clear their memory and then report
-them as not defined anymore, but you shouldn't do that unless you don't
-plan to use them again, because it saves time when you load them up
-again to have memory already ready to be filled. The normal way to
-free up space used by an aggregate is to assign the empty list.
-
-This counterintuitive behavior of C<defined> on aggregates may be
-changed, fixed, or broken in a future release of Perl.
-
See also L</undef>, L</exists>, L</ref>.
=item delete EXPR
PERL_CKDEF(ck_bitop)
PERL_CKDEF(ck_concat)
PERL_CKDEF(ck_delete)
+PERL_CKDEF(ck_defined)
PERL_CKDEF(ck_eof)
PERL_CKDEF(ck_eval)
PERL_CKDEF(ck_exec)
(Maybe you meant system() when you said exec()?
exec "true" ; my $a
+ defined(@array) is deprecated (and not really meaningful)
+ (Maybe you should just omit the defined()?)
+ defined @a ;
+ my @a ; defined @a ;
+ defined (@a = (1,2,3)) ;
+
+ defined(%hash) is deprecated (and not really meaningful)
+ (Maybe you should just omit the defined()?)
+ defined %h ;
+ my %h ; defined %h ;
__END__
# op.c
EXPECT
Statement unlikely to be reached at - line 4.
(Maybe you meant system() when you said exec()?)
+########
+# op.c
+use warning 'deprecated' ;
+defined(@a);
+EXPECT
+defined(@array) is deprecated (and not really meaningful) at - line 3.
+(Maybe you should just omit the defined()?)
+########
+# op.c
+use warning 'deprecated' ;
+my @a; defined(@a);
+EXPECT
+defined(@array) is deprecated (and not really meaningful) at - line 3.
+(Maybe you should just omit the defined()?)
+########
+# op.c
+use warning 'deprecated' ;
+defined(@a = (1,2,3));
+EXPECT
+defined(@array) is deprecated (and not really meaningful) at - line 3.
+(Maybe you should just omit the defined()?)
+########
+# op.c
+use warning 'deprecated' ;
+defined(%h);
+EXPECT
+defined(%hash) is deprecated (and not really meaningful) at - line 3.
+(Maybe you should just omit the defined()?)
+########
+# op.c
+use warning 'deprecated' ;
+my %h; defined(%h);
+EXPECT
+defined(%hash) is deprecated (and not really meaningful) at - line 3.
+(Maybe you should just omit the defined()?)