# from Hans Dieter Pearcey
# on Wednesday 12 May 2010 08:49:
>...just because it's not how arrays work anywhere else in Perl,
This is not about how arrays work, but how functions work. See
localtime(), caller(), each(), glob(), readline(), etc.
But then see sort() and split().
There are reasonable cases for context sensitivity, with some reasons
better than others. It's easy to wrongly think you've found a good use
for it, and maybe even easier to get angry when it is used well but
catches you off guard.
>but even the relatively simple "return an array in list context, or an
>arrayref in scalar context" ...
That might be simple, but no builtins do this, which seems to say
something. If you're still working with lists, you expect them to
behave like lists, and not try to package themselves in a reference
with postage to Cairo. The only case where wantarray ? (@x) : [...@x]
even has utility is in e.g. perl5i trying to allow method chaining on
list objects without needing an explicit ->flatten, but that is just a
horrible hack workaround to the lack of a "method" context IMO. It
might be worth the caveats, but that just makes it "good enough", not
a "good idea".
>or because I have to remember
> that even though I got an arrayref when I wrote '$foo = function()',
> I'll get a list back when I write 'bar(x => 1, y => function(), z =>
> 3)'.
perlfunc:
"In general, they do what you want, unless you want consistency."
--Eric
--
Cult: A small, unpopular religion.
Religion: A large, popular cult.
-- Unknown
---------------------------------------------------
http://scratchcomputing.com
---------------------------------------------------