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
