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.

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

Consider processing your file a line at a time, instead of slurping all of it into a variable for processing:

Code

use strict; use warnings;

my $old = pop; my $new = pop;

while (<>) { s/^(module\s+)\Q$old\E/$1$new/; print; }

Usage: perl script.pl inFile 'new' 'old' [>outFile]

The "new" and "old" arguments passed to the script are popped off @ARGV for use later in the substitution regex. Since the word "module" starts a line that you want to update, the s/^ ... notation forces a match at the beginning of the line. quotemeta (\Q ... \E) is used on $old in case it contains any regex characters. The substitution is implicitly done on the default scalar $_ and that scalar is also implicitly printed.