[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] regex help



(I have the feeling there'll be some linewrap promlems with this mail)
I'm creating a droplet to correct an error made on many pages for work. Unfortunately I cannot get it to work quite. At the very bottom of this mail is the code in question (the rest of the droplet works fine). Basically there's an image map at the tops of all the pages that currently looks like...

<MAP name="map1">
<AREA shape="rect" coords="380,28,457,55" href="timeline.html">
<AREA shape="rect" coords="5,28,59,56" href="Maps/map_index.html">
<AREA shape="rect" coords="237,27,369,53" href="lingtables/ling_index.htm">
<AREA shape="rect" coords="82,31,124,53" href="texts/texts.htm">
<AREA shape="rect" coords="149,29,223,57" href="images/images_index.html">
<AREA shape="rect" coords="11,4,165,29" href="formosa_index.html">
</MAP>
<IMG usemap="#map1" src="../images/images.titlebar.GIF" width="467" height="60" border="0" align="top">

...with the src of the image varying. What the error is and what I hope to do is count the number of "../" strings in the image's src. (in this case 1) then append to the beginning of the hrefs for each section of the imagemap. Getting something like...

<MAP name="map1">
<AREA shape="rect" coords="380,28,457,55" href="../timeline.html">
<AREA shape="rect" coords="5,28,59,56" href="../Maps/map_index.html">
<AREA shape="rect" coords="237,27,369,53" href="../lingtables/ling_index.htm">
<AREA shape="rect" coords="82,31,124,53" href="../texts/texts.htm">
<AREA shape="rect" coords="149,29,223,57" href="../images/images_index.html">
<AREA shape="rect" coords="11,4,165,29" href="../formosa_index.html">
</MAP>
<IMG usemap="#map1" src="../images/images.titlebar.GIF" width="467" height="60" border="0" align="top">

...I've tried many variations of the code below, but all to no avail; each garners a different error in the output. I'm sure it's something simple I just can't find it. (ps the code below is a functioning snipit of the full code)

le meas,
--Nick

#!perl
$file = $ARGV[0];





             open FILE, "<$file" or die "unable to open '$file'";
               while (<FILE>) {
                    if ($_ =~ /<IMG usemap="#map1" src="(.*)titlebar\.GIF" width="467" height="60" border="0" align="top">/) {
                         $bug = $1;
                         $back = $bug =~ tr/\.\.\//\.\.\//;
                         undef $bug;
                    }
               }
               close FILE;
               open FILE, "+<$file" or die "unable to open '$file'";
               while (<FILE>) {
                    if ($_ =~ /(<AREA shape="rect" coords="380,28,457,55" href="timeline\.html">)/) {
                         $bug = '<AREA shape="rect" coords="380,28,457,55" href="';
                         $bug .= '../' x $back;
                         $bug .= 'timeline.html">';
                         s/$1/$bug/;
                         print FILE;
                    } elsif ($_ =~ /(<AREA shape="rect" coords="5,28,59,56" href="Maps\/map_index\.html">)/) {
                         $bug = '<AREA shape="rect" coords="5,28,59,56" href="';
                         $bug .= '../' x $back;
                         $bug .= 'Maps/map_index.html">';
                         s/$1/$bug/;
                         print FILE;
                    } elsif ($_ =~ /(<AREA shape="rect" coords="237,27,369,53" href="lingtables\/ling_index\.htm">)/) {
                         $bug = '<AREA shape="rect" coords="237,27,369,53" href="';
                         $bug .= '../' x $back;
                         $bug .= 'lingtables/ling_index.htm"';
                         s/$1/$bug/;
                         print FILE;
                    } elsif ($_ =~ /(<AREA shape="rect" coords="82,31,124,53" href="texts\/texts\.htm">)/) {
                         $bug = '<AREA shape="rect" coords="82,31,124,53" href="';
                         $bug .= '../' x $back;
                         $bug .= 'texts/texts.htm">';
                         s/$1/$bug/;
                         print FILE;
                    } elsif ($_ =~ /(<AREA shape="rect" coords="149,29,223,57" href="images\/images_index\.html">)/) {
                         $bug = '<AREA shape="rect" coords="149,29,223,57" href="';
                         $bug .= '../' x $back;
                         $bug .= 'images/images_index.html">';
                         s/$1/$bug/;
                         print FILE;
                    } elsif ($_ =~ /(<AREA shape="rect" coords="11,4,165,29" href="formosa_index\.html">)/) {
                         $bug = '<AREA shape="rect" coords="11,4,165,29" href="';
                         $bug .= '../' x $back;
                         $bug .= 'formosa_index.html">';
                         s/$1/$bug/;
                         print FILE;
                    }
                    print FILE;
               }
               close FILE;
__END__

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org