"David L. Nicol" wrote:
> 
> What if its a method of anything in an array?  $_ is already
> a reference to the object on the array in for loops rather
> than a copy of it.  What if we make change be not something about
> for loops, but about anything in an array?
> 
>         print "The index, in its array, of <<$_>> is $CORE::ARRAY_INDEX{$_}"
> 
> where %CORE::ARRAY_INDEX is a very magical system-provided hash that
> tells us the index in its array of something that is in an array.  It
> is often undefined; and would get tricky but definable for objects that
> can be in multiple containers at once, I'd think it would be the index
> of the item in the most recent container it was accessed from.
> 
> If we are going to have arrays that can be sparse, we've pretty much got
> to keep track of this info somehow anyway, so might as well give a way
> to access it.

I think an array element, being a scalar value, should not be aware of
the array it's a part of.  You should be able to go from array to value,
but not back.  Think about it: elements can be part of multiple arrays
at the same time, a reference to an element will persist even if the
element is shifted off the array, etc.

What might be useful instead, is to define a function that can be used
on the control variable of a foreach loop:

  foreach my $elem (@array) {
    print "The value of array elem '", position($elem), "' is
'$elem'\n";
  }

Hildo

Reply via email to