[Israel.pm] Gabor's problem with newbies

Gaal Yahas gaal at forum2.org
Sun Dec 28 05:17:14 PST 2008


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 <jason.elbaum at gmail.com> 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 <jason.elbaum at gmail.com> 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 <peter at pg-consultants.com> wrote:
>>>
>>> I deleted the email, but from what I remember the problem is:
>>>
>>> @argv = "123456"
>>> split("4", at 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", at argv)
>>>
>>> results in 1,3
>>> It is the result of the count of the elements being split.
>>>
>>> Peter
>>>
>>>
>>>
>>> _______________________________________________
>>> Perl mailing list
>>> Perl at perl.org.il
>>> http://perl.org.il/mailman/listinfo/perl
>>
> _______________________________________________
> Perl mailing list
> Perl at perl.org.il
> http://perl.org.il/mailman/listinfo/perl
>



-- 
Gaal Yahas <gaal at forum2.org>
http://gaal.livejournal.com/



More information about the Perl mailing list