diff options
author | Matthew Horsfall (alh) <wolfsage@gmail.com> | 2011-11-16 23:06:33 -0500 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-11-18 17:46:21 -0800 |
commit | e508c8a4ba3a6febe681a5f59949b1d403b124bd (patch) | |
tree | bc1e0ac587fd09743c1e645c36bd889b4e334e1c /op.c | |
parent | 18f5643bfee3e4c35fe1b510ad2e37dcb28b9efc (diff) | |
download | perl-e508c8a4ba3a6febe681a5f59949b1d403b124bd.tar.gz |
Throw a helpful warning when someone tries length(@array) or length(%hash)
Diffstat (limited to 'op.c')
-rw-r--r-- | op.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -9664,6 +9664,39 @@ Perl_ck_each(pTHX_ OP *o) return o->op_type == ref_type ? o : ck_fun(o); } +OP * +Perl_ck_length(pTHX_ OP *o) +{ + PERL_ARGS_ASSERT_CK_LENGTH; + + o = ck_fun(o); + + if (ckWARN(WARN_SYNTAX)) { + const OP *kid = o->op_flags & OPf_KIDS ? cLISTOPo->op_first : NULL; + + if (kid) { + switch (kid->op_type) { + case OP_PADHV: + case OP_RV2HV: + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), + "length() used on %%hash (did you mean \"scalar(keys %%hash)\"?)"); + break; + + case OP_PADAV: + case OP_RV2AV: + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), + "length() used on @array (did you mean \"scalar(@array)\"?)"); + break; + + default: + break; + } + } + } + + return o; +} + /* caller is supposed to assign the return to the container of the rep_op var */ STATIC OP * |