NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
arrays with negative indices (Score:1)
I would've thought that C would do something horrid like (type)*(array - index), but my C is lousy.
rjbs
Re:arrays with negative indices (Score:2)
Re:arrays with negative indices (Score:1)
After all the -1 subscript is "first existing element from the right" not "a new element at the end." Or am I being thick?
rjbs
Re:arrays with negative indices (Score:2)
@foo = ();
$foo[10] = "foo"; # legal
$foo[-10] = "foo"; # illegal
In the former case, index 10 does not exist. I create it and indices 0 to 9 now exist as undef. In the latter case, index -10 does not exist, but I cannot assign to it. Why not allow me to assign to a negative index on an empty array?
Re:arrays with negative indices (Score:1)
You want $foo[-10] = "foo" to be the same as @foo = ( (undef) x $m, "foo", (undef) x $n ), but what are $m and $n ? (On reflection, $m should probably be zero and $n be 9? What's the benefit of this behavior?)
Does $foo[-10] = $bar[-5] = "foo" result in @foo being a different size than @bar ? (Based on our reflection above, they would be different sizes.)
If @foo is already defined, then what happens when we use a negative index that takes us off the left? (We are already allowed to use a positive index that takes us off the right--this maintains the symmetry we are seeking.) Do we pad the right with undefs? Or do we shift everything to the right by padding the left with undefs? How do we break the symmetry between the two selections (padding the right vs. padding the left/shifting to the right)? Both can be consistent with our desired behavior for previously empty arrays.
Reply to This
Parent