I guess I need to clarify that a little more.... maybe this will help.

$text_to_find = qq~<script LANGUAGE="JAVASCRIPT">
<!--
VendorSite= "Companycom";
VendorPage= "CompanyMail";
VendorWidth= 468;
VendorHeight= 60;
VendorPrintTag= true;
VendorNewAd= true;
VendorLoaded= false;
VendorVersion= 3.2;
file://-->
</script>
<script
SRC="http://Vendor.com/ads/" LANGUAGE="JAVASCRIPT"></script>
<script
LANGUAGE="JAVASCRIPT">
<!--
if (VendorLoaded) VendorDeliverAd();
file://-->
</script>
<NOSCRIPT> <a target="_top"
HREF="http://Vendor.com/server/click/Compancom/CompanyMail/123"><img
SRC="http://Vendor.com/server/ad/Companycom/CompanyMail/123" border="0"
width="468" height="60"></a>
</NOSCRIPT>~;

$replacement_text = "<IMG SRC="http://www.Company.com/ads/default.gif'>";

s/$text_to_find/$replacement_text/gi;



----- Original Message -----
From: "Chris Dugmore" <[EMAIL PROTECTED]>
To: "Matthew J. Brooks" <[EMAIL PROTECTED]>
Cc: "Boston Perl Mongers" <[EMAIL PROTECTED]>
Sent: Tuesday, March 20, 2001 9:10 AM
Subject: Re: [Boston.pm] multiline search and replace


> Matthew,
>
> I am not sure this is best way but I am sure there is more than one way. I
> presumed you are using a superior operating system (*nix) so
> you could use the find utility to recurse through the directory tree
finding
> each *.html and executing a perl script that makes a backup of the
original
> file and then substitutes the changefrom text to changeto.
>
> find /path/to/files -name *.html -exec perl -pi.bak -e \
> 's/changefrom/changeto/' {} \;
>
> In your second message, I am not sure what part of the javascript you want
to
> change. Is it the following:
>
> <img SRC="http://Vendor.com/server/ad/Companycom/CompanyMail/123"
>
> and should change to:
>
> <IMG SRC="http://www.Company.com/ads/default.gif"
>
> If this is what you want put the vendor line in the changefrom (remember
to \
> the /)
>
> <img SRC="http:\/\/Vendor.com\/server\/ad\/Companycom\/CompanyMail\/123"
>
> and your replacement text in the changeto.
>
> This isn't the most flexible approach as it is targetted to one specific
string
> but it should get the job done.
>
> Best of luck,
> Chris Dugmore
> ps. advanced perl users should feel free to comment on this approach.
>
> "Matthew J. Brooks" wrote:
>
> > I trying to write a script to replace some multiline javascript code
with a
> > single <A HREF> tag. To compound this problem, I have to get the script
to
> > recurse through the directories so I don't have to execute it over and
over
> > for the hundreds of html (and htm) files in multiple directories on the
> > webserver.
> >
> > I've tried various approaches, but I'm out of options (and time).
> >
> > Anyone have some input on how to best do this? Or maybe some scratch
code I
> > can tinker with?
> >
> > Thanks,
> > Matthew
>
>
> _________________________________________________________
> Do You Yahoo!?
> Get your free @yahoo.com address at http://mail.yahoo.com
>

Reply via email to