[% setvar title length(@ary) deserves a warning %]
|Note: these documents may be out of date. Do not use as reference!|
To see what is currently happening visit http://www.perl6.org/
length(@ary) deserves a warning
Maintainer: Nathan Torkington <email@example.com> Date: 15 Sep 2000 Mailing List: firstname.lastname@example.org Number: 238 Version: 1 Status: Developing Supercedes: RFC 212
Beginners often try
length(@ary) (which has bizarre consequences and
no real purpose). Make it emit a warning.
Beginners think of the size of an array as its length, so try to use the length() function to find this information. They should be told by the compiler that this is not correct.
The warning would be triggered when Perl finds an array in scalar context as the argument to length(). The construct serves no useful purpose otherwise, so backwards compatibility isn't a problem.
While I originally suggested "just make it work", this would (1) steer users away from the real understanding of context; (2) require changes to the prototype system to permit length() to still be overridable. While it is a good idea to do what users want, in this case I've been convinced that the user would benefit from being told the correct way to do it.
When you check a length() function call, warn if its argument is a scalar-context array.
RFC 212: (retired) Make length(@array) work
perlfunc manpage for information on the length() function