THRAK has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w use strict; my @text_remove = ('[TEXT-2]', '[TEXT-4]', '[TEXT-7]'); my @xlate_data = ('[TEXT-1] Data Test ', '[TEXT-2] Second line tacked +onto #1', '[TEXT-3] Line #3', '[TEXT-4] 4th line goes with #3', '[TEX +T-5] five-five-FIVE', '[TEXT-6] Five was a Zappa reference...', '[TEX +T-7] This is a longer entry. But really not much different. I should + be part of #6'); my $rm_pos = 0; foreach my $move (@text_remove) { print "O: $rm_pos ~ $move\n"; my $xlate_pos = 0; foreach my $data (@xlate_data) { if ($data =~ /^\Q$move\E/) { print "I: $rm_pos ~ $move ~ $data\n\n"; $data =~ s/^\Q$move\E\s*/ /; $xlate_data[$xlate_pos -1] .= $data; splice(@xlate_data, $xlate_pos, 1); #remove entry to short +en loops } $xlate_pos++; # splice(@text_remove, $rm_pos, 1); #remove token entry to shorten +loops } $rm_pos++; } foreach (@xlate_data) { print "NOW: $_\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Reducing Array Interations
by blakem (Monsignor) on Aug 16, 2001 at 01:55 UTC | |
by THRAK (Monk) on Aug 16, 2001 at 17:45 UTC | |
by blakem (Monsignor) on Aug 17, 2001 at 02:03 UTC | |
by THRAK (Monk) on Aug 17, 2001 at 15:53 UTC | |
|
Re: Reducing Array Interations
by arturo (Vicar) on Aug 16, 2001 at 02:40 UTC | |
by THRAK (Monk) on Aug 16, 2001 at 17:48 UTC | |
|
Re: Reducing Array Interations
by I0 (Priest) on Aug 16, 2001 at 02:34 UTC |