[Boulder.pm] Trickey (for a newbie) String Replacement

Peter Hutnick pm at hutnick.com
Wed May 5 13:39:37 CDT 2004


Hello,

I'm writing a little script to do some of the grunt-work of converting a 
LaTeX document to XHTML.

Consider the following block of code:

@rule=( 's/\\emph{(.*?)}/\<em\>$1\<\/em\>/g',
         's/\\chapter{(.*)}/\<h1\>$1\<\/h1\>/g');

         foreach (@rule) {
print $_, ";\n";
                 $text =~ $_;
         }

As, I'm sure you can see, this does nothing.  I think you can also see 
what I am driving at.

The obvious fix is to break each element of @rule down into two strings. 
    (I.e. a hash or an array of arrays.)  For my application that leaves 
two problems.

1. This significantly increases the complexity of what should be a 
simple script.  (It makes loading the rules harder.  It makes calling 
the subs more complex.)

2. I imagine that some of my rules are /not/ going to be in the form 
s/$search/$replace/g.  I'd like to have the flexibility of doing a tr 
for example.

Is there a better way to approach this?


Thanks,
Peter



More information about the Boulder-pm mailing list