in reply to Smart Search and Replacement with RegEx

I wouldn't try to do it all in a jumbo regex. Why not a simple split?
sub translate { my $str = shift; my @chunks = split /<(\d+)>/ => $str; my @results; while (@chunks) { my ($number, $string) = splice @chunks => 0, 2; if ($number == 30) { ... } else { push @results => '@(' . $hash {$number} . ')', qq {"$string"}; } } join ";" => @results; }

Abigail

Replies are listed 'Best First'.
Re: Re: Smart Search and Replacement with RegEx
by shelob101 (Sexton) on May 31, 2002 at 02:32 UTC
    very nice! I've never used the parenthetical technique in split before, but after playing with it, this seems to do the breakup and keep your search pattern instead of throwin g it away. Also the splice keeps the string stuff in order and still moves the pointer through the while loop. Thanks for showing me a couple of new tricks, Abigail