H
H.S.
Hello,
I am trying to make changes to a website made by somebody else,
apparently in Dreamweaver. I do not have that application to work with
(never used it) and I am working in Linux only (Debian, Etch).
I have searched google on how to do this and have written a small perl
script in the process. I am quite knew to perl (not new to Linux and
have some basic knowledge of expression matching in sed and grep).
I want to replace the following code (which may or may not be on a
single line):
##############################################
<td height="30" valign="top"><a href="db/index.php"
onmouseout="MM_swapImgRestore()"
onmouseover="MM_swapImage('db','','img_after.gif',1)"><img
name="db" border="0" src="img_before.gif" width="100" height="30"></a></td>
###############################################
with a slightly modified expression. For simplicity, let us say I want
to replace it with "CHANGED" string. Note that the above code is just a
part of the HTML file which contains similar code before and after this
para (consequently, it will have <td>.*</td> before and after this para).
Here is my attempt at doing this:
############################################
#!/usr/bin/perl
local $/; # slurp mode ( to read the file into a var )
#define the name of the data file to modify
my $data_file="intro.php";
#open the data file
open DAT, $data_file or die "Could not open file: $!";
#variable to hold the data file (it will hold *all* of it!)
my $contents;
#read in the contents of the data file
$contents=<DAT>;
#print the file contents
#print $contents;
if ($contents =~ s/<td.*db_before.*td>/CHANGED/s){
print $contents;
print "Changed\n";
}
############################################
The problem is, I think, that it matches the very first <td and
continues on till a td/> after db_before. From the results, this is not
working at all. Suggestions? Or even a different way to perform this
editing? The editing is to be performed on this block of code on many
files. And as I said earlier, the block of code is either in the shape I
mentioned above or is on one single. The latter case is not a problem.
thanks,
->HS
I am trying to make changes to a website made by somebody else,
apparently in Dreamweaver. I do not have that application to work with
(never used it) and I am working in Linux only (Debian, Etch).
I have searched google on how to do this and have written a small perl
script in the process. I am quite knew to perl (not new to Linux and
have some basic knowledge of expression matching in sed and grep).
I want to replace the following code (which may or may not be on a
single line):
##############################################
<td height="30" valign="top"><a href="db/index.php"
onmouseout="MM_swapImgRestore()"
onmouseover="MM_swapImage('db','','img_after.gif',1)"><img
name="db" border="0" src="img_before.gif" width="100" height="30"></a></td>
###############################################
with a slightly modified expression. For simplicity, let us say I want
to replace it with "CHANGED" string. Note that the above code is just a
part of the HTML file which contains similar code before and after this
para (consequently, it will have <td>.*</td> before and after this para).
Here is my attempt at doing this:
############################################
#!/usr/bin/perl
local $/; # slurp mode ( to read the file into a var )
#define the name of the data file to modify
my $data_file="intro.php";
#open the data file
open DAT, $data_file or die "Could not open file: $!";
#variable to hold the data file (it will hold *all* of it!)
my $contents;
#read in the contents of the data file
$contents=<DAT>;
#print the file contents
#print $contents;
if ($contents =~ s/<td.*db_before.*td>/CHANGED/s){
print $contents;
print "Changed\n";
}
############################################
The problem is, I think, that it matches the very first <td and
continues on till a td/> after db_before. From the results, this is not
working at all. Suggestions? Or even a different way to perform this
editing? The editing is to be performed on this block of code on many
files. And as I said earlier, the block of code is either in the shape I
mentioned above or is on one single. The latter case is not a problem.
thanks,
->HS