I am trying to modify all the href links on the website to a javascript. I wrote a perl module to search and replace the text. But I couldnt able to end the bracket opened for the javascript. Any ideas on how to close the bracket opened for the javascript.
Thanks in advance
Orginal href text in a page.
<a href="/exitPage/index.jsp?tname=offers&amp;tsrc=ownermag&amp;type=l +ink" onmouseover="rollover('offers','img/offers_on.gif');" onmouseout +="rollover('offers','img/offers_off.gif');"><img src="img/offers_off. +gif" width="139" height="16" alt="" border="0" name="offers"></a>

Modified text :-

<a href="javascript:flexWin('?tname=offers&amp;tsrc=ownermag&amp;type= +link" onmouseover="rollover('offers','img/offers_on.gif');" onmouseou +t="rollover('offers','img/offers_off.gif');"><img src="img/offers_off +.gif" width="139" height="16" alt="" border="0" name="offers"></a>


Perl Module :-

#!/usr/bin/perl #the path to the files $serverpath = "/default/main/test"; #the docs you want changed $doctype = "html"; #the string to look for $find = "/exitPage/index.jsp?"; #what you want to replace it with $replace = "javascript:flexWin('"; #ok, getting started print "Finding \"$find\" and replacing it with \"$replace\"\n"; #going to directory opendir(DIR, "$serverpath"); #looking for files @files = grep(/\.$doctype$/,readdir(DIR)); closedir(DIR); #lining the files up foreach $file(@files){ $pa_fi = "$serverpath/$file"; #opening the file to read it print "opening file $pa_fi\n"; open(FILE,"$pa_fi"); my(@subm) = <FILE>; close(FILE); #backup the document rename $pa_fi, $pa_fi . '.bac'; print "making backup\n"; $n=0; #printing new foreach $line (@subm) { $line =~ s/$find/$replace/g; open(SUB,">>$pa_fi"); print SUB $line; close(SUB); $n++; } print "$n lines searched in $file\n"; }

In reply to String manipulation by infyniti

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.