
March 9th, 2013, 06:27 AM
|
|
Registered User
|
|
Join Date: Mar 2013
Posts: 2
Time spent in forums: 7 m 46 sec
Reputation Power: 0
|
|
|
Match at begin not ^ working for in my script
Hi all, i need to debug this script and make it work according to my requirement. This is an urgent requirement, i need to fix this asap.</p> The concept of the script was to replace "oldname" written after the word "module" with "newname" This worked well until the word module came in the comment.
CONTENT OF SCRIPT <code> #!/usr/bin/perl -w
BEGIN {undef $/;}
# I TRIED 1ST my $match = "^module.*?$ARGV[2].*?([\\(;])"; 2ND my $match = "\^module.*?$ARGV[2].*?([\\(;])"; 3RD my $match = "\\^module.*?$ARGV[2].*?([\\(;])"
my $match = "module.*?$ARGV[2].*?([\\(;])";
#print "$match";
my $filename = $ARGV[0];
open (INFILE, "<", $filename) or die "Failed to read file $filename : $! \n";
$string = <INFILE>;
close INFILE;
#I ALSO TRIED "$string =~ s/^$match/module $ARGV[1]$1/sg;";
$string =~ s/$match/module $ARGV[1]$1/sg;
open OUTFILE, ">$ARGV[0]" || die "Failed to create $ARGV[0]\n";
print OUTFILE ($string);
close OUTFILE;<\code>
what this script does to input file is : CONTENT OF BEFORE SCIPT IS RUN ON FILE <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word here the script goofs up
`timescale 1ps/10fs
module OLD(Y, A, B );
output Y;
input A;
input B;
endmodule
</code> NOW I RUN <code>script.pl FILE NEW OLD</code> now the CONTENT OF FILE BECOMES <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word here the script goofs up
`timescale 1ps/10fs
module NEW(Y, A, B );
output Y;
input A;
input B;
endmodule
</code> which is good but if i write the word "module" in the comment line i.e. CONTENT OF BEFORE SCrIPT IS RUN ON FILE which goofs up
<code>
//Verilog HDL for "tt", "hh" "functional"
// if i write the word module here the script goofs up
`timescale 1ps/10fs
module OLD(Y, A, B );
output Y;
input A;
input B;
endmodule </code>
Now the contents become <code>//Verilog HDL for "tt", "hh" "functional"
// if i write the word module NEW(Y, A, B );
output Y;
input A;
input B;
endmodule
</code> which is unacceptable to me. plz help guys,
|