develooper Front page | perl.perl6.language.subs | Postings from September 2000

Re: RFC 212 (v1) Make length(@array) work

From:
Bart Lateur
Date:
September 13, 2000 04:00
Subject:
Re: RFC 212 (v1) Make length(@array) work
Message ID:
bbnurskac8j430e697c97j49svv509llma@4ax.com
On Wed, 13 Sep 2000 08:37:57 +0100, Hildo Biersma wrote:

>> Make length(@array) work
>
>Counter-proposal: make length(@array) a syntax error. I don't feel like
>rewarding stupidity, I'd rather teach people how to do things properly.

Indeed. What about lists?

	print length(qw(a b c));

Should this return 3?

If so, what will this return?

	print length('abc');

Is the argument not a list of one item? So, should this print 1, or 3?

Note that similar functions that work on both scalars and lists, such as
reverse(), use the context in which it is called. so,

	print reverse 'qwerty';

will still print 'qwerty', while

	print scalar reverse 'qwerty';

prints 'ytrewq'.

Note that this trick can't be used here, because length() only returns a
scalar.

-- 
	Bart.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About