So now i have 2 scripts, one which is doing all work correctly but does NOT USE LINE BY LINE match the code is as follows #!/usr/bin/perl -w
BEGIN {undef $/;}
# I TRIED 1ST my $match = "^module.*?$ARGV[2].*?([\\(;])"; 2ND my $mat
+ch = "\^module.*?$ARGV[2].*?([\\(;])"; 3RD my $match = "\\^module.*?$
+ARGV[2].*?([\\(;])"
#"(?<=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 TRIED "$string =~ s/^$match/module $ARGV[1]$1/sg;";
$string =~ s/$match/$ARGV[1]$1/sg;
#print "$1";
open OUTFILE, ">$ARGV[0]" || die "Failed to create $ARGV[0]\n";
print OUTFILE ($string);
close OUTFILE;
this will do well until in the comment// some1 writes our pattern. Now to come up with a new script which GOES LINE BY LINE courtesy @CountZero i have use Modern::Perl;
my $filename = $ARGV[0];
die "Usage: modulenamechanger.pl filename newmodulename oldmodulename\
+n"
unless @ARGV == 3;
open my $INFILE, "<", $filename or die "Failed to read file $filename
+: $!";
say "Now parsing $filename";
my @file = <$INFILE>;
close $INFILE;
open my $OUTFILE, '>', $filename or die "Failed to create $filename";
my $match = qr "module\s*($ARGV[2])";
say "Matching: $match";
for my $line (@file) {
if ( $line =~ m(^//) ) {
print $OUTFILE $line;
next;
}
$line =~ s/$match/module $ARGV[1]/;
print $OUTFILE $line;
}
But my problems with this are as follows:
1. NO modern perl
2.This code didnt work for me
3.I dont want to change the pattern regex my $match = "(?<=module )$ARGV[2].*?([\\(;])";(it may cause some other effect because im not 100% sure about its intent and why it was written in that way, so lets keep it that way only).
4. I didnt find any else portion in your code @zerocount
5.Also there is some problem in parsing, i have modified your code but still not getting desired o/p. Please see the below code, i cant find out whats wrong ,i tried various print statements as well to see but in vain #!/usr/bin/perl -w
BEGIN {undef $/;}
#use Modern::Perl;
my $filename = $ARGV[0];
die "Usage: modulenamechanger.pl filename newmodulename oldmodulename\
+n"
unless @ARGV == 3;
open my $INFILE, "<", $filename or die "Failed to read file $filename
+: $!";
print "Now parsing $filename\n";
my @file = <$INFILE>;
close $INFILE;
open my $OUTFILE, '>', $filename or die "Failed to create $filename";
# WITHOUT ABANSAL CONCEPT my $match = qr "module\s*($ARGV[2])";
my $match = "(?<=module )$ARGV[2].*?([\\(;])";
print "Matching: $match\n";
for my $line (@file) {
print "READING LINE $line \n";
if ( $line =~ m(^//) ) {
print "INSIDE IF\n";
print $OUTFILE $line;
next;
}
else
{
print "INSIDE ELSE \n BEFORE change:\t $line\n";
$line =~ s/$match/moduleXXX $ARGV[1]/;
print "AFTER :\t $line\n";
print $OUTFILE $line;
next;
}
}
The output is my.pl f7 NEW OLD
Now parsing f7
Matching: (?<=module )OLD.*?([\(;])
READING LINE //Verilog HDL for "tt", "hh" "functional"
// if i write the word module OLD(Y, A, B ); here the script goofs up
`timescale 1ps/10fs
module OLD(Y, A, B );
output Y;
input A;
input B;
endmodule
INSIDE IF
|