Hello,

please try to help the fresher

i was a beginner in perl .but gave me critical work.

my task looks simple!But not.i was trying for 4days.


i have two text files each contain code in modules.


my task i have to take module name from the user

and search the module by module name in file.whenever module is found


i have to take the content in the module into on string


or array ,ETc


similarly i have to perform the search in 2nd file also and finally

compare the content in the modules and print the code which is different.


i can able to search upto module name.then after i can't

module looks like

(i have to search the module first upto i_MMCM_ADV then after take the contents after

brackets into dummy variable upto semilcolan(end))

for anothe i have to do the same and compare the contents


.CLKIN1_PERIOD ( 5.000000 ),
.CLKIN2_PERIOD ( 5.000000 ),
.LOC ( "MMCM_ADV_X0Y5" ),
.VCOCLK_FREQ_MAX ( 1200.000000 ),
.VCOCLK_FREQ_MIN ( 600.000000 ),
.CLKIN_FREQ_MAX ( 700.000000 ),
.CLKIN_FREQ_MIN ( 10.000000 ),
.CLKPFD_FREQ_MAX ( 450.000000 ),
.CLKPFD_FREQ_MIN ( 10.000000 ))
start i_MMCM_ADV (
.CLKFBIN(CLKFBIN),
.PSCLK(GND),
.PWRDWN(\i_MMCM_ADV/PWRDWN_INT ),
.DCLK(GND),
.DEN(GND),
.CLKINSEL(\i_MMCM_ADV/CLKINSEL_INT ),
.CLKIN2(GND),
.RST(\i_MMCM_ADV/RST_INT ),
.PSINCDEC(\i_MMCM_ADV/PSINCDEC_INT ),
.DWE(GND),
.PSEN(\i_MMCM_ADV/PSEN_INT ),
.CLKIN1(clk_IBUF_2571),
.CLKOUT3(CLKOUT3),
.CLKOUT3B(\i_MMCM_ADV/CLKOUT3B ),
.CLKFBOUT(CLKFBOUT),
.CLKFBSTOPPED(\i_MMCM_ADV/CLKFBSTOPPED ),
.CLKFBOUTB(\i_MMCM_ADV/CLKFBOUTB ),
.CLKOUT1(CLKOUT1),
.CLKOUT5(CLKOUT5),
.DRDY(\i_MMCM_ADV/DRDY ),
.CLKOUT0(clk_out0_OBUF_2333),
.CLKOUT4(CLKOUT4),
.CLKOUT1B(\i_MMCM_ADV/CLKOUT1B ),
.CLKINSTOPPED(\i_MMCM_ADV/CLKINSTOPPED ),
.CLKOUT0B(\i_MMCM_ADV/CLKOUT0B ),
.CLKOUT2(CLKOUT2),
.CLKOUT2B(\i_MMCM_ADV/CLKOUT2B ),
.PSDONE(\i_MMCM_ADV/PSDONE ),
.CLKOUT6(CLKOUT6),
.LOCKED(LOCKED_OBUF_2386),
.DI({GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND}),
.DADDR({GND, GND, GND, GND, GND, GND, GND}),
.DO({\i_MMCM_ADV/DO15 , \i_MMCM_ADV/DO14 , \i_MMCM_ADV/DO13 , \i_MMCM_ADV/DO12 , \i_MMCM_ADV/DO11 , \i_MMCM_ADV/DO10 , \i_MMCM_ADV/DO9 ,
\i_MMCM_ADV/DO8 , \i_MMCM_ADV/DO7 , \i_MMCM_ADV/DO6 , \i_MMCM_ADV/DO5 , \i_MMCM_ADV/DO4 , \i_MMCM_ADV/DO3 , \i_MMCM_ADV/DO2 , \i_MMCM_ADV/DO1 ,
\i_MMCM_ADV/DO0 })
); END
X_SRLC16E #(
.LOC ( "SLICE_X0Y102" ),
.INIT ( 16'h0000 ))
\dsync_r6/Mshreg_dout_0 (
.A0(1'b0),
.A1(1'b0),
.A2(1'b0),
.A3(1'b0),
.CLK(\NlwBufferSignal_dsync_r6/Mshreg_dout_0/CLK ),
.D(r6[0]),
.Q15(\NLW_dsync_r6/Mshreg_dout_0_Q15_UNCONNECTED ),
.Q(\dsync_r6/Mshreg_dout_0_303 ),
.CE(1'b1)

The first part, storing the contents of the files into string variables and then extracting the module code from each into two string variables:

#!/usr/bin/perl
#extract_mods_to_strings.pl
use strict;
use warnings;
my $dir = '/home/david/Programming/Perl/data';
my $filename1 = '1.txt';
my $filename2 = '2.txt';

#The following way of 'slurping' files into strings adapted from
# http://www.perlmonks.org/?node_id=287647

my $string1 = do {
    local $/;
    open my $handle1,'<',"$dir/$filename1" or die "open of $dir/$filename1 failed: $!\n";
    <$handle1>;
    }; # $string1 now contains contents of 1.txt

my $string2 = do {
    local $/;
    open my $handle2,'<',"$dir/$filename2" or die "open of $dir/$filename2 failed: $!\n";
    <$handle2>;
    }; # $string2 now contains contents of 2.txt

$string1 =~ /i_MMCM_ADV \((.*)\);/s;
my $modcode_from_1 = $1;

$string2 =~ /i_MMCM_ADV \((.*)\);/s;
my $modcode_from_2 = $1;

print "Here is the module code from $filename1---------------------:\n";
print $modcode_from_1;
print "\n\n";
print "Here is the module code from $filename2---------------------:\n";
print $modcode_from_2;

I don't know how the comparison should be done and what constitutes a unit of code to compare and print.

Hi,

code is working but problem is

i was getting code after the module also i.e after semicolan also.

i want get code upto first semicolan only.
(i_MMCM_ADV/DO0)

then after i should comapare the strings and print the differences.

please make the changes please try to solve me

#!/usr/bin/perl
#compare_files.pl
use strict;
use warnings;
my $dir = '/home/david/Programming/Perl/data';
my $filename1 = '1.txt';
my $filename2 = '2.txt';

sub slurp_file {
    #This subroutine takes the path and filename of an input file
    # and returns a filehandle referencing the entire contents.
    my ($dir,$file) = @_;
    local $/;
    open my $fh,'<',"$dir/$file" or die "open of $dir/$file failed: $!\n";
    <$fh>;
    };

my $string1 = slurp_file($dir, $filename1); # $string1 now contains contents of 1.txt

my $string2 = slurp_file($dir, $filename2); # $string2 now contains contents of 2.txt

$string1 =~ /i_MMCM_ADV \(([^;]*)\);/s;
my $modcode_from_1 = $1;
undef $string1; #Don't need $string1 any more.
$modcode_from_1 =~ s/[[:cntrl:]]//gm; #Remove control characters

$string2 =~ /i_MMCM_ADV \(([^;]*)\);/s;
my $modcode_from_2 = $1;
undef $string2; #Don't need $string2 any more.
$modcode_from_2 =~ s/[[:cntrl:]]//gm; #Remove control characters

my @codes1 = split /\./, $modcode_from_1;
my @codes2 = split /\./, $modcode_from_2;

printf "%-35s %s\n", $filename1, $filename2;
my $i = 0;
foreach (@codes1) {
    unless ($codes1[$i] eq $codes2[$i]) {
        printf "%-35s is not the same as %s\n", $codes1[$i], $codes2[$i];
    }
    $i++;
}

Running this prints the following output:

1.txt                               2.txt
CLKIN1(clk_IBUF_7819),              is not the same as CLKIN1(clk_IBUF_2571),    
CLKOUT0(clk_out0_OBUF_7848),        is not the same as CLKOUT0(clk_out0_OBUF_2333),    
LOCKED(i_MMCM_ADV_ML_NEW_I1),       is not the same as LOCKED(LOCKED_OBUF_2386),
commented: excellent answer +1

i was very much thankful to you for your great timely help.

code is working like gem.

You are welcome. Please mark the thread solved. It helps keep our forum organised. :)

Hi,
The code works for i_MMCM_ADV
But not working for X_MMCM_ADV

My requirement is reg expression starting x_MMCM_ADV
and end with semicolan in I_MMCM_ADV module

first file
X_MMCM_ADV #(
.CLOCK_HOLD ( "FALSE" ),
.CLKOUT4_CASCADE ( "FALSE" ),
.BANDWIDTH ( "OPTIMIZED" ),
.CLKFBOUT_USE_FINE_PS ( "FALSE" ),
.CLKOUT0_USE_FINE_PS ( "FALSE" ),
.CLKOUT1_USE_FINE_PS ( "FALSE" ),
.CLKOUT2_USE_FINE_PS ( "FALSE" ),
.CLKOUT3_USE_FINE_PS ( "FALSE" ),
.CLKOUT4_USE_FINE_PS ( "FALSE" ),
.CLKOUT5_USE_FINE_PS ( "FALSE" ),
.CLKOUT6_USE_FINE_PS ( "FALSE" ),
.COMPENSATION ( "ZHOLD" ),
.STARTUP_WAIT ( "FALSE" ),
.CLKFBOUT_MULT_F ( 5.000000 ),
.CLKFBOUT_PHASE ( 0.000000 ),
.CLKOUT0_DIVIDE_F ( 10.000000 ),
.CLKOUT0_DUTY_CYCLE ( 0.500000 ),
.CLKOUT0_PHASE ( 0.000000 ),
.CLKOUT1_DUTY_CYCLE ( 0.500000 ),
.CLKOUT1_PHASE ( 0.000000 ),
.CLKOUT2_DUTY_CYCLE ( 0.500000 ),
.CLKOUT2_PHASE ( 0.000000 ),
.CLKOUT3_DUTY_CYCLE ( 0.500000 ),
.CLKOUT3_PHASE ( 0.000000 ),
.CLKOUT4_DUTY_CYCLE ( 0.500000 ),
.CLKOUT4_PHASE ( 0.000000 ),
.CLKOUT5_DUTY_CYCLE ( 0.500000 ),
.CLKOUT5_PHASE ( 0.000000 ),
.CLKOUT6_DUTY_CYCLE ( 0.500000 ),
.CLKOUT6_PHASE ( 0.000000 ),
.REF_JITTER1 ( 0.010000 ),
.REF_JITTER2 ( 0.010000 ),
.CLKOUT1_DIVIDE ( 20 ),
.CLKOUT2_DIVIDE ( 40 ),
.CLKOUT3_DIVIDE ( 60 ),
.CLKOUT4_DIVIDE ( 80 ),
.CLKOUT5_DIVIDE ( 100 ),
.CLKOUT6_DIVIDE ( 120 ),
.DIVCLK_DIVIDE ( 1 ),
.CLKIN1_PERIOD ( 5 ),
.CLKIN2_PERIOD ( 5 ),
.LOC ( "MMCM_ADV_X0Y0" ),
.VCOCLK_FREQ_MAX ( 1200.000000 ),
.VCOCLK_FREQ_MIN ( 600.000000 ),
.CLKIN_FREQ_MAX ( 700.000000 ),
.CLKIN_FREQ_MIN ( 10.000000 ),
.CLKPFD_FREQ_MAX ( 450.000000 ),
.CLKPFD_FREQ_MIN ( 10.000000 ))
i_MMCM_ADV (
.CLKFBIN(CLKFBIN),
.PSCLK(GND),
.PWRDWN(\i_MMCM_ADV/PWRDWN_INT ),
.DCLK(GND),
.DEN(GND),
.CLKINSEL(\i_MMCM_ADV/CLKINSEL_INT ),
.CLKIN2(GND),
.RST(\i_MMCM_ADV/RST_INT ),
.PSINCDEC(\i_MMCM_ADV/PSINCDEC_INT ),
.DWE(GND),
.PSEN(\i_MMCM_ADV/PSEN_INT ),
.CLKIN1(clk_IBUF_7819),
.CLKOUT3(CLKOUT3),
.CLKOUT3B(\i_MMCM_ADV/CLKOUT3B ),
.CLKFBOUT(CLKFBOUT),
.CLKFBSTOPPED(\i_MMCM_ADV/CLKFBSTOPPED ),
.CLKFBOUTB(\i_MMCM_ADV/CLKFBOUTB ),
.CLKOUT1(CLKOUT1),
.CLKOUT5(CLKOUT5),
.DRDY(\i_MMCM_ADV/DRDY ),
.CLKOUT0(clk_out0_OBUF_7848),
.CLKOUT4(CLKOUT4),
.CLKOUT1B(\i_MMCM_ADV/CLKOUT1B ),
.CLKINSTOPPED(\i_MMCM_ADV/CLKINSTOPPED ),
.CLKOUT0B(\i_MMCM_ADV/CLKOUT0B ),
.CLKOUT2(CLKOUT2),
.CLKOUT2B(\i_MMCM_ADV/CLKOUT2B ),
.PSDONE(\i_MMCM_ADV/PSDONE ),
.CLKOUT6(CLKOUT6),
.LOCKED(i_MMCM_ADV_ML_NEW_I1),
.DI({GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND}),
.DADDR({GND, GND, GND, GND, GND, GND, GND}),
.DO({\i_MMCM_ADV/DO15 , \i_MMCM_ADV/DO14 , \i_MMCM_ADV/DO13 , \i_MMCM_ADV/DO12 , \i_MMCM_ADV/DO11 , \i_MMCM_ADV/DO10 , \i_MMCM_ADV/DO9 ,
\i_MMCM_ADV/DO8 , \i_MMCM_ADV/DO7 , \i_MMCM_ADV/DO6 , \i_MMCM_ADV/DO5 , \i_MMCM_ADV/DO4 , \i_MMCM_ADV/DO3 , \i_MMCM_ADV/DO2 , \i_MMCM_ADV/DO1 ,
\i_MMCM_ADV/DO0 })
);


Second file


X_MMCM_ADV #(
.CLOCK_HOLD ( "FALSE" ),
.CLKOUT4_CASCADE ( "FALSE" ),
.BANDWIDTH ( "OPTIMIZED" ),
.CLKFBOUT_USE_FINE_PS ( "FALSE" ),
.CLKOUT0_USE_FINE_PS ( "FALSE" ),
.CLKOUT1_USE_FINE_PS ( "FALSE" ),
.CLKOUT2_USE_FINE_PS ( "FALSE" ),
.CLKOUT3_USE_FINE_PS ( "FALSE" ),
.CLKOUT4_USE_FINE_PS ( "FALSE" ),
.CLKOUT5_USE_FINE_PS ( "FALSE" ),
.CLKOUT6_USE_FINE_PS ( "FALSE" ),
.COMPENSATION ( "EXTERNAL" ),
.STARTUP_WAIT ( "FALSE" ),
.CLKFBOUT_MULT_F ( 5.000000 ),
.CLKFBOUT_PHASE ( 0.000000 ),
.CLKOUT0_DIVIDE_F ( 10.000000 ),
.CLKOUT0_DUTY_CYCLE ( 0.500000 ),
.CLKOUT0_PHASE ( 0.000000 ),
.CLKOUT1_DUTY_CYCLE ( 0.500000 ),
.CLKOUT1_PHASE ( 0.000000 ),
.CLKOUT2_DUTY_CYCLE ( 0.500000 ),
.CLKOUT2_PHASE ( 0.000000 ),
.CLKOUT3_DUTY_CYCLE ( 0.500000 ),
.CLKOUT3_PHASE ( 0.000000 ),
.CLKOUT4_DUTY_CYCLE ( 0.500000 ),
.CLKOUT4_PHASE ( 0.000000 ),
.CLKOUT5_DUTY_CYCLE ( 0.500000 ),
.CLKOUT5_PHASE ( 0.000000 ),
.CLKOUT6_DUTY_CYCLE ( 0.500000 ),
.CLKOUT6_PHASE ( 0.000000 ),
.REF_JITTER1 ( 0.010000 ),
.REF_JITTER2 ( 0.010000 ),
.CLKOUT1_DIVIDE ( 20 ),
.CLKOUT2_DIVIDE ( 40 ),
.CLKOUT3_DIVIDE ( 60 ),
.CLKOUT4_DIVIDE ( 80 ),
.CLKOUT5_DIVIDE ( 100 ),
.CLKOUT6_DIVIDE ( 120 ),
.DIVCLK_DIVIDE ( 1 ),
.CLKIN1_PERIOD ( 5.000000 ),
.CLKIN2_PERIOD ( 5.000000 ),
.LOC ( "MMCM_ADV_X0Y5" ),
.VCOCLK_FREQ_MAX ( 1200.000000 ),
.VCOCLK_FREQ_MIN ( 600.000000 ),
.CLKIN_FREQ_MAX ( 700.000000 ),
.CLKIN_FREQ_MIN ( 10.000000 ),
.CLKPFD_FREQ_MAX ( 450.000000 ),
.CLKPFD_FREQ_MIN ( 10.000000 ))
i_MMCM_ADV (
.CLKFBIN(CLKFBIN),
.PSCLK(GND),
.PWRDWN(\i_MMCM_ADV/PWRDWN_INT ),
.DCLK(GND),
.DEN(GND),
.CLKINSEL(\i_MMCM_ADV/CLKINSEL_INT ),
.CLKIN2(GND),
.RST(\i_MMCM_ADV/RST_INT ),
.PSINCDEC(\i_MMCM_ADV/PSINCDEC_INT ),
.DWE(GND),
.PSEN(\i_MMCM_ADV/PSEN_INT ),
.CLKIN1(clk_IBUF_2571),
.CLKOUT3(CLKOUT3),
.CLKOUT3B(\i_MMCM_ADV/CLKOUT3B ),
.CLKFBOUT(CLKFBOUT),
.CLKFBSTOPPED(\i_MMCM_ADV/CLKFBSTOPPED ),
.CLKFBOUTB(\i_MMCM_ADV/CLKFBOUTB ),
.CLKOUT1(CLKOUT1),
.CLKOUT5(CLKOUT5),
.DRDY(\i_MMCM_ADV/DRDY ),
.CLKOUT0(clk_out0_OBUF_2333),
.CLKOUT4(CLKOUT4),
.CLKOUT1B(\i_MMCM_ADV/CLKOUT1B ),
.CLKINSTOPPED(\i_MMCM_ADV/CLKINSTOPPED ),
.CLKOUT0B(\i_MMCM_ADV/CLKOUT0B ),
.CLKOUT2(CLKOUT2),
.CLKOUT2B(\i_MMCM_ADV/CLKOUT2B ),
.PSDONE(\i_MMCM_ADV/PSDONE ),
.CLKOUT6(CLKOUT6),
.LOCKED(LOCKED_OBUF_2386),
.DI({GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND, GND}),
.DADDR({GND, GND, GND, GND, GND, GND, GND}),
.DO({\i_MMCM_ADV/DO15 , \i_MMCM_ADV/DO14 , \i_MMCM_ADV/DO13 , \i_MMCM_ADV/DO12 , \i_MMCM_ADV/DO11 , \i_MMCM_ADV/DO10 , \i_MMCM_ADV/DO9 ,
\i_MMCM_ADV/DO8 , \i_MMCM_ADV/DO7 , \i_MMCM_ADV/DO6 , \i_MMCM_ADV/DO5 , \i_MMCM_ADV/DO4 , \i_MMCM_ADV/DO3 , \i_MMCM_ADV/DO2 , \i_MMCM_ADV/DO1 ,
\i_MMCM_ADV/DO0 })
);

i have changed the module names and tried by changing the RE but error or warning comes says modules not initialized

Finally I was in SUCCESS.

use strict;
use warnings;
#use Getopt::Long;  
  #my $filename1;
  #my $filename2;
  #my $modul;
   #my @args    = @ARGV;
  #print "Getting the options";
 # my $ok = &GetOptions("args"     => sub { &PrintArgs(\@args) },
#		       "h|help|?" => sub { &Help },
3		       "filename1=s"      => \$filename1,
#		       "filename2=s"      => \$filename2,
#		       "modul=s" => \$modul);
#		  print "\n\n";
#		   print " --------------------------------File1: $filename1 #File2:$filename2	-------------------------------------\n\n\n\n";


my $modul='X_MMCM_ADV';
my $filename1 = 'ise_routed.v';
my $filename2 = 'rodin_routed.v';



my $string1 = readfile( $filename1); 

my $string2 = readfile( $filename2); 


sub readfile {
  
    my ($file) = @_;
    local $/;
    open my $fh,'<',"$file" or die "open of $file failed: $!\n";
    <$fh>;
    };




 
$string1 =~ /$modul #\(([^;]*)\);/s;
my $modcode_from_1 = $1;
#print "$modcode_from_1";
open (MYFILE, '>module1.txt');
print MYFILE "$modcode_from_1\n";
close (MYFILE); 
undef $string1; 
$modcode_from_1 =~ s/[[:cntrl:]]//gm; 


$string2 =~ /$modul #\(([^;]*)\);/s;
my $modcode_from_2 = $1;
#print "$modcode_from_2";
open (MYFILE1, '>module2.txt');
print MYFILE1 "$modcode_from_2\n";
close (MYFILE1); 
undef $string2; 
$modcode_from_2 =~ s/[[:cntrl:]]//gm; 



my @codes1 = split /\./, $modcode_from_1;

my @codes2 = split /\./, $modcode_from_2;


print "\t\t****************THE DIFFERENCES IN THE FILES ARE AS FOLLOWS****************\n\n\n";

printf "\t\t\t%-45s %s\n\n\n", $filename1, $filename2;

my $i = 0;
foreach (@codes1) {
    unless ($codes1[$i] eq $codes2[$i]) {
        
        printf "\t%-45s is not the same as %s\n\n", $codes1[$i], $codes2[$i];


    
    }
    
    
    
    $i++;
}

we get module1 and module 2 from the two files

which i have uploaded.

But actually the problem is i was not listing differences correctly

i have uploade the output image also

but actually that number of differences are not there.

only 6 to 8 diifferences are ther so how to handle this problem

i was much concentrated on modules comparision

actually dot is splitting parameter,so it was creating this unusual o/p.i have tried with other comma delimeters but output is tooooooooooo much disturbed

spliting parameter is dot so this created the problem.i have tried with comma and dot as splitting paramter but not working

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.