Greg London wrote:
> From: David Cantrell <da...@cantrell.org.uk>
>> On Mon, Sep 27, 2010 at 11:15:17PM -0400, Uri Guttman wrote:
>>> actually the <= part is even more amusing. look here:
>>> perl -le '$#foo = -2 ; print $#foo'
>>> -1
>>> you can't set the last index to < -1. which makes sense. which makes the
>>> original code even dumber.
>> $ perl -le '$[=-1; print $#foo'
>> -2
> Congrabulashuns. You just won the "Evil programmer of the Year" award.

Yay!

But I don't want to even think about the collision between Unspeakable
Evil like that and the Other Unspeakable Evil of negative indices on
*normal* arrays.

Cos you did all know that in this code, for example:

  $[ = 0; # :-)
  @array = qw(ant bat cat dog elephant);
  print $array[-1];
  print $array[-2];

will print 'elephant' and 'dog', right?  This is occasionally Very
Useful, although perhaps not as clear as just using $#array, $#array-1
etc.  Unfortunately it doesn't wrap around twice, so $array[-6] isn't
also 'elephant'.

$[ is scheduled for removal from perl in 5.14, I believe.  And in all
versions of perl 5 it is at least file-scoped so can't leak out of modules.

-- 
David Cantrell | semi-evolved ape-thing

    Planckton: n, the smallest possible living thing

_______________________________________________
Boston-pm mailing list
Boston-pm@mail.pm.org
http://mail.pm.org/mailman/listinfo/boston-pm

Reply via email to