in reply to Regular Expression Loop Hell
From your description, it sounds like you want something like this (mildly tested):
update: removed line in the code that compiled the RE. I don't think it adds anything in the way of understanding.#!/usr/bin/perl use strict; my @animals = ( "bear<1>\n", "camel<0> <2>\n", "<2>horse\n", "duck<3>\ +n" ); my %changemap = ( "<0>" => 'A', "<1>" => 'B', "<2>" => 'C', "<3>" => 'D', ); # build a single regular expression to match all of the # items we're changing from my $from = join '|', keys %changemap; for (@animals) { s/($from)/$changemap{$1}/g; } print @animals; __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression Loop Hell
by Roy Johnson (Monsignor) on Mar 07, 2006 at 22:32 UTC |