infyniti has asked for the wisdom of the Perl Monks concerning the following question:
<a href="/exitPage/index.jsp?tname=offers&tsrc=ownermag&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>
<a href="javascript:flexWin('?tname=offers&tsrc=ownermag&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>
#!/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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: String manipulation
by tlm (Prior) on Apr 04, 2005 at 14:32 UTC | |
|
Re: String manipulation
by phaylon (Curate) on Apr 04, 2005 at 14:19 UTC |