in reply to Test if variable is equal to a bracket?
use strict; use warnings; my @arr = qw{[ A ] B C [ D ] E F [ G ] H I}; my $idx = $#arr; while ( $idx >= 2 ) { if ( $arr[$idx] eq q{]} ) { splice @arr, $idx - 2, 0, join q{}, splice @arr, $idx - 2, 3; $idx -= 3; } else { $idx --; } } print qq{$_\n} for @arr;
The output is
[A] B C [D] E F [G] H I
I hope this is useful.
Cheers,
JohnGG
|
|---|