shelob101 has asked for the wisdom of the Perl Monks concerning the following question:
And so on. The pieces that look like <\d+> are what I'm interested in. What this should be replaced with is:10 PRINT "<29>This should be dim.<30>EThis should be reversed.<28>This + is bold."
OK, no problem. So I set up a hash with keys in it like '<29>' and a value like '@(-38);'. And, using the /g switch of the pattern match operator, I can do:10 PRINT @(-38);"This should be dim.";@(-37);"This should be reversed. +";@(-40);"This is bold."
I've ignored the codes like <30>E because they are a slighty different pattern, and I want to keep the code simple so I can set up a similar loop for those.while ($line=~/(<\d+>)/g) { next if ($1 eq '<30>'); $line=~s/$1/$fix{$1}/; }
Thanks for any ideas
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(tye)Re: Smart Search and Replacement with RegEx
by tye (Sage) on May 29, 2002 at 17:38 UTC | |
by sfink (Deacon) on May 29, 2002 at 18:59 UTC | |
by shelob101 (Sexton) on May 31, 2002 at 02:36 UTC | |
|
Re: Smart Search and Replacement with RegEx
by Abigail-II (Bishop) on May 30, 2002 at 13:36 UTC | |
by shelob101 (Sexton) on May 31, 2002 at 02:32 UTC | |
|
Re: Smart Search and Replacement with RegEx aka I am not crazy, I am insane.
by Jenda (Abbot) on May 29, 2002 at 20:04 UTC |