in reply to Reducing Array Interations
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 %text_remove; @text_remove{@text_remove} = @text_remove; foreach my $xlate_pos (1..$#xlate_data) { my $data = $xlate_data[$xlate_pos]; if( $text_remove{($data=~/^(\[[\w-]+\])/)[0]} ){ $data =~ s/^\[[\w-]\]\s*/ /; $xlate_data[$xlate_pos -1] .= $data; $xlate_data[$xlate_pos] = ''; } } @xlate_data = grep{$_}@xlate_data; foreach (@xlate_data) { print "NOW: $_\n"; }
|
|---|