Oh, there exist places where list length is useful. Haven't you ever
done "1 .. @foo" or "unless @foo == 2"?
I don't really get the "reasonable person" argument. I never met
anyone (who didn't know C and) thought to write
if (!strcmp("desired", actual)) {
puts("okay, you got what you wanted.");
/* Yes, I'm aware this is the library and not the language, but it's
* standard enough.
* If you disagree, at least grant that there are examples to be
* given with pointers. */
}
That said, even today I occasionally make mistakes with context, like
$match = /..(.....)../ or (shudder) $arg = @_. But personally I just
view these as silly slips that I occasionally make, not as language
misfeatures. Perl 6 (you knew this was coming) will do away with the
second error, since parameter handling is no longer manual. I _don't
want_ to do away with list-to-scalar conversion because it's very
often useful.
Scalar hash conversion is a whole different matter...
On Sun, Dec 28, 2008 at 3:00 PM, Jason Elbaum <[email protected]> wrote:
> If you ask me, this is a bug in the semantics of Perl. Based on the
> principle of Do What I Mean, it's entirely unreasonable for a list in
> a scalar context to be converted to its length. I can't conceive of
> any reasonable person who would consider that to be "what they mean"
> when they write $x = @abc - unless, of course, they're already
> familiar with Perl's semantics. Not to mention when they write (and
> lots of confused beginners do this) $x = ( 'abc' ). And not to mention
> the difference between how we take the length of an array, the length
> of a string, and the size of a hash.
>
> This is perhaps the most blatant instance where DWIM differs from Do
> What Perl Thinks I Mean. Ideally, it should be deprecated and warned
> against, but no doubt there's too much live code to make that
> feasible.
>
> Chag sameach,
>
> Jason Elbaum
>
>
> On Sun, Dec 28, 2008 at 2:57 PM, Jason Elbaum <[email protected]> wrote:
>>
>> If you ask me, this is a bug in the semantics of Perl. Based on the
>> principle of Do What I Mean, it's entirely unreasonable for a list in a
>> scalar context to be converted to its length. I can't conceive of any
>> reasonable person who would consider that to be "what they mean" when they
>> write $x = @abc - unless, of course, they're already familiar with Perl's
>> semantics. Not to mention when they write (and lots of confused beginners do
>> this) $x = ( 'abc' ). And not to mention the difference between how we take
>> the length of an array, the length of a string, and the size of a hash.
>>
>> This is perhaps the most blatant instance where DWIM differs from Do What
>> Perl Thinks I Mean. Ideally, it should be deprecated and warned against, but
>> no doubt there's too much live code to make that feasible.
>>
>> Chag sameach,
>>
>> Jason Elbaum
>>
>>
>>
>>
>> On Sun, Dec 28, 2008 at 2:51 PM, Peter Gordon <[email protected]>
>> wrote:
>>>
>>> I deleted the email, but from what I remember the problem is:
>>>
>>> @argv = "123456"
>>> split("4",@argv)
>>>
>>> The context forces @argv to a scalar, much like $n = @argv.
>>> So the @argv tranlsates to 1.
>>>
>>>
>>> A more convincing example is:
>>>
>>> @argv = ("123456") x 123
>>> split("2",@argv)
>>>
>>> results in 1,3
>>> It is the result of the count of the elements being split.
>>>
>>> Peter
>>>
>>>
>>>
>>> _______________________________________________
>>> Perl mailing list
>>> [email protected]
>>> http://perl.org.il/mailman/listinfo/perl
>>
> _______________________________________________
> Perl mailing list
> [email protected]
> http://perl.org.il/mailman/listinfo/perl
>
--
Gaal Yahas <[email protected]>
http://gaal.livejournal.com/
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl