summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorMatthew Horsfall (alh) <wolfsage@gmail.com>2011-11-16 23:06:33 -0500
committerFather Chrysostomos <sprout@cpan.org>2011-11-18 17:46:21 -0800
commite508c8a4ba3a6febe681a5f59949b1d403b124bd (patch)
treebc1e0ac587fd09743c1e645c36bd889b4e334e1c /op.c
parent18f5643bfee3e4c35fe1b510ad2e37dcb28b9efc (diff)
downloadperl-e508c8a4ba3a6febe681a5f59949b1d403b124bd.tar.gz
Throw a helpful warning when someone tries length(@array) or length(%hash)
Diffstat (limited to 'op.c')
-rw-r--r--op.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/op.c b/op.c
index 63e5a4a14b..6d0736da00 100644
--- a/op.c
+++ b/op.c
@@ -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 *