[Israel.pm] Gabor's problem with newbies

Jason Elbaum jason.elbaum at gmail.com
Sun Dec 28 05:00:57 PST 2008


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
>



More information about the Perl mailing list