perlquestion
Cody Pendant
<P>I'm working on the reformatting of a number of documents.
<P>
I not only have to repetitively apply a number of regexes to a number of pages, but apply some regexes to some pages and not others.
<P>
There's no right or wrong answer of course, but how might Monks go about this in an organised and maintainable way, apart of course from the straightforward process of just doing:
<code>
$html =~ s/foo/bar/;
$html =~ s/baz/quux/;
$html =~ s/monkey/pants/;
</code>
and the variation
<code>
$html =~ s/foo/bar/;
if($baz_quux_replacement_required){
$html =~ s/baz/quux/;
}
$html =~ s/monkey/pants/;
</code>
<P>
Would monks for instance use a data structure like this:
<code>
$replacements =
[
['foo','bar'],
['baz','quux']
];
</code>
or even this:
<code>
$replacements =
{
fix_foo => ['foo','bar'],
fix_baz => ['baz','quux']
};
</code>
and then iterate through them? Would you create a sub and feed it the RHS and LHS as arguments every time? Or just a for() loop?
<P>
I'd be interested in Monkly opinions.
<!-- Node text goes above. Div tags should contain sig only -->
<div class="pmsig"><div class="pmsig-87399">
<HR>
<BR>
<blockquote>
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')<br>
=~y~b-v~a-z~s; print
</blockquote>
</div></div>