
kencl
User
Oct 9, 2003, 4:35 AM
Post #1 of 3
(7490 views)
|
Nicer way to do this?
|
Can't Post
|
|
Hi Folks, Took me a while to realize that the pattern was gobbling up the trailing single pipe, but here's what I came up with. Does anyone see a "neater" way of doing this, or would you consider this a good solution? my $list = 'one|two|three|four'; my %changes = (one => 1, three => 3); $list =~ s/\|/\|\|/g; # double up pipes $list =~ s/((^|\|)(.*?)(\||$))/ exists($changes{$3}) ? $2 . $changes{$3} . $4 : $1/ge; $list =~ s/\|\|/\|/g; # single up pipes print $list; # produces 1|two|3|four
Thanks! >> If you can't control it, improve it, correlate it or disseminate it with PERL, it doesn't exist!
|