in reply to Concatenating Array elements
First off, arrays have a 0-based index. For example:
my @array = 1..10; print "Index 7 (before): $array[7]\n"; print "Index 8 (before): $array[8]\n"; $array[7] = $array[7] . $array[8]; print "Index 7 (after): $array[7]\n"; print "Index 8 (after): $array[8]\n";
Would yield:
Index 7 (before): 8 Index 8 (before): 9 Index 7 (after): 89 Index 8 (after): 9
If you want to have an element disappear when concatenated elsewhere, you could use splice:
$array[7] = $array[7] . splice @array, 8, 1;
Your method: 1 2 3 4 5 6 7 89 9 10 Splice method: 1 2 3 4 5 6 7 89 10
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Concatenating Array elements
by wilmer_t (Novice) on Aug 19, 2014 at 21:54 UTC | |
by soonix (Canon) on Aug 20, 2014 at 07:13 UTC |
In Section
Seekers of Perl Wisdom