in reply to Concatenating Array elements

Your example demonstrates an off-by-one error: $array[7] contained 8 to begin with, and afterward, would contain 89.

This is one of those things that you could easily try yourself. If you have Perl installed, you would do this:

my @array = ( 1 .. 10 ); $array[7] = $array[7] . $array[8]; print "$array[7]\n"; print "$array[8]\n";

And you will see the following output:

89 9

...which would tell you that $array[8] hasn't been modified in any way. As a matter of fact, it would be a really difficult to use language if something as innocuous as the concatenation operator could modify its operands (not counting stringification). Imagine this:

my @array = ( 1 .. 10 ); $array[7] = $array[7] + $array[8]; print "$array[7]\n"; print "$array[8]\n";

There, you would expect to see:

17 9

And you would complain if simple addition caused one of the operands to vaporize. Concatenation is not so different, in this regard.

Now if it is your intention to vaporize an element in an array and shift everything past that point up to fill the void, look at splice, but be forewarned that shifting elements to lower indices is an O(n) operation, meaning that it consumes as much computational time as it takes to shift one element, then to shift the next one, then to shift the next one, and so on, until done -- as the array grows, the time grows linearly.


Dave