Hi,

I have two files and each consists of modules and in turn modules consists of some verilog

data and instances.i have to search for module name in the two files and comapare the

contents of the modules in the two files.

i have code it does module search,extract the contents of modules and compare

them and print the differnces.

BUT THE PROBLEM IS

I have same module 10 to 15 times in each file.

so what i have to do is take the the module name and for all occurrances

of module i have to take content in itand compare with other file

same module contents.but both the files have equal modules.

i was sending the files as attchements

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

$modul='X_RAMB18E1';
$string1 = readfile( $filename1); 
$string2 = readfile( $filename2); 


if($modul eq 'X_MMCM_ADV' or $modul eq 'X_RAMB18E1' or $modul eq 'X_RAMB36E1' or $modul eq 'X_FIFO36E1')
{
&mod1;
}
elsif($modul eq 'i_MMCM_ADV')
{
 &mod2;
}
else
{
print "module not found";
}

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

sub Help {
 $tmp = '\$';
print <<EOF
Usage\:perl pr2.pl -filename1 ise_routed.v -filename2 rodin_routed.v -modul X_MMCM_ADV
This script is used to generate a  report of differences between modules of 
file1 and file2taking module as another input parameter.
so according to the module name module based comparision will be done
EOF
    ;
exit 0;
}

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

$string2 =~ /$modul #\(([^;]*)\);/s;
$modcode_from_2 = $1;
open (MYFILE1, '>module2.txt');
print MYFILE1 "$modcode_from_2\n";
close (MYFILE1); 
undef $string2; 
$modcode_from_2 =~ s/[[:cntrl:]]//gm; 
@codes1 = split /\,/,  $modcode_from_1;
@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;
$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++;
}
}

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

$string2 =~ /$modul \(([^;]*)\);/s;
$modcode_from_2 = $1;
open (MYFILE1, '>module2.txt');
print MYFILE1 "$modcode_from_2\n";
close (MYFILE1); 
undef $string2; 
$modcode_from_2 =~ s/[[:cntrl:]]//gm; 
@codes1 = split /\,/,  $modcode_from_1;
@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;
$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++;
}

suppose if we take X_RAMB18E1 module it is present 15 times in each file.

but different is instances.so i have to take module in on file and compare it with other and print the diff.again upto the last occurance of module i have to do that.

so if select the X_RAMB18E1 comparision should be done in all 15 and print the differences


file1 file2 instance name


X_RAMB18E1 is occured 15 times each occurance has an instance different.

it below lock parameter in code.

i have uploaded the instances also.


'PLEASE TRY TO HELP ME"

YOU HELP ME FOR ONE ONE MODULE I WILL WORK FOR OTHER BY REFERENCE

For the purpose of giving a simple example of extracting more than one instance from a string, I hard-coded a sample string instead of reading from your files. Notice that you can store the instances in an array instead of a single scalar variable.

#!/usr/bin/perl
use strict;
use warnings;

my $string_of_instances = <<END;
SIMPLE_MODULE #(
aa
bb
cc
dd
);

SIMPLE_MODULE #(
aa
bx
cx
dd
);

END

my @instances = $string_of_instances =~ /SIMPLE_MODULE #\(([^;]*)\);/gs;
my $count_of_instances = @instances;
print "Found $count_of_instances instances of SIMPLE_MODULE in the string.\n";

foreach (@instances){
    do_something($_);
}

sub do_something{
    #This subroutine is just a stub.
    #You can add logic to do what you want for each instance.
    my $mod_instance = shift(@_); #Assign passed parameter
    print "The following is one of the instances:\n$mod_instance\n";
    print '-' x 70, "\n";
}

Running the above prints the following output:

Found 2 instances of SIMPLE_MODULE in the string.
The following is one of the instances:

aa
bb
cc
dd

----------------------------------------------------------------------
The following is one of the instances:

aa
bx
cx
dd

----------------------------------------------------------------------

Hi,
the example was very useful for this basic programmer and working for 0ne instance.


in short my problem is

1. read the rwo files
2.take the contnt of files
3.find the module

3.compare the file1 X_RAMB18E1 and file 2 X_RAMB18E1

4.for each and every time and print the differences


so for example if X_RAMB18E1 occurs "n" times in file1

and X_RAMB18E1 occurs "n" time in file. n is not known

if n =15
i have to print differences for 15 times occuranceBut actually what i want is to print the differences
for first occurances print the differences
for second and so on

between number of same modules of same name in two files.
i was able toextract the instrance
in each module by RE

instance is some what like

1.) \U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO1/rx_fifo_i/ramgen_u

instance in X_RAMB18E1 for the first time

2.) \U_eth_aggregator_tb/eth_aggregator/core_0/central_memory/Mram_txmemory8

instance in X_RAMB18E1 for module occurance for the second time


like wise X_RAMB18E1 occurs 18 times each with different instance.

in the example file1 i have send only two modules of X_RAMB18E1


SO WHAT i want is if i give any module name the code should check occurance of module

if occurs then it should take the content of module from #( to semicolan

so upto now i can do this only for one module at a time.

i was trying to excute with while loop the code but i was unable....

#!/usr/bin/perl
use strict;
use warnings;

my $filename1='/home/david/Programming/Perl/data/filename1.txt';
my $filename2='/home/david/Programming/Perl/data/filename2.txt';

my $modul='X_RAMB18E1';
my $string1 = readfile( $filename1);
my $string2 = readfile( $filename2); 
$string1 =~ s/[[:cntrl:]]//gm; #Might as well get rid of newlines, etc. now
$string2 =~ s/[[:cntrl:]]//gm; #Might as well get rid of newlines, etc. now

#Extract instances of module from first file
$string1 =~ /($modul\s#\(.*\);)/gs;
my $string_of_instances_from_1 = $1;
undef $string1;
my @instances_1 = $string_of_instances_from_1 =~ /$modul #\(([^;]*)\);/g;
my $count_of_instances_1 = @instances_1;
print "Found $count_of_instances_1 instances of $modul in the string.\n";

#Extract instances of module from first file
$string2 =~ /($modul\s#\(.*\);)/gs;
my $string_of_instances_from_2 = $1;
undef $string2;
my @instances_2 = $string_of_instances_from_2 =~ /$modul #\(([^;]*)\);/g;
my $count_of_instances_2 = @instances_2;
print "Found $count_of_instances_2 instances of $modul in the string.\n";


die "$filename1 doesn't have same number of instances of $modul as $filename2!"
    unless $count_of_instances_1 == $count_of_instances_2;

my $i;
foreach(0..$#instances_1){
    $i = $_ + 1;
    print "Comparing Instance $i:-----------------------------------\n";
    compare_instances($_);
}

sub compare_instances{
    my $idx = shift @_; #Assign passed parameter to index variable
    my $modcode_from_1 = $instances_1[$idx];
    my $modcode_from_2 = $instances_2[$idx];
    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++;
    }
}

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

hi,
Thanks a lot for ur script it works with a bullet speed.

you are a great perl scripter.

Hi,

some simple code required.i was trying but i was unable.

i have turned the code u have devloped to work exactly with my requirement.

.But i want instances to get printed each time like we are printing comparing instance name.

suppose if we take

Each X_RAMB18E1 module consists of different instances like in file1
for the first time

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO1/rx_fifo_i/ramgen_u   (
for the second time
 \U_eth_aggregator_tb/eth_aggregator/core_0/central_memory/Mram_txmemory8  (

Each X_RAMB18E1 module consists of different instances like in file2
for the first time

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO1/rx_fifo_i/ramgen_u  (
for the second time
 \U_eth_aggregator_tb/eth_aggregator/core_0/central_memory/Mram_txmemory8  (

Now i want regular expression

to find the code starting with

\U_eth_aggregator_tb/eth_aggregator/core_0/ and ending with opening bracket.

and print the line.along with comparing instance1 (here i want the extaracted string) like

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO1/rx_fifo_i/ramgen_u

for each every cccurance of module the instance is different

so i shouls use the same RE.but each insatance has same properties like starting with

\U_eth_aggregator_tb/eth_aggregator/core_0/ and ending with open bracket.

in short iwant RE starting with \U_eth_aggregator_tb/eth_aggregator/core_0/ and ending

with bracket.all the code is in @codes1 as u know. from codes1 i have to extract the instance with RE

I think that for this we don't need to extract the separate instances and split the codes. We can apply the regex to the string from the file instead. This time we don't remove the newlines.

#!/usr/bin/perl
use strict;
use warnings;

#Prepare regex pattern as follows (better to prepare complex rexex in advance)
my $pattern = '\\\U_eth_aggregator_tb/eth_aggregator/core_0/.+\(';
my $re = qr/$pattern/m;

my $filename1='/home/david/Programming/Perl/data/filename1.txt';

my $modul='X_RAMB18E1';
my $string1 = readfile( $filename1);

my $count = 0;
my @matches = $string1 =~ m/$re/g;
foreach (@matches){
        $count++;
        print "Occurence number $count of the pattern:\n$_\n\n";
}

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

Running the above on the filename1.txt that you attached gives the following output:

Occurence number 1 of the pattern:
\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_l  (

Occurence number 2 of the pattern:
\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_u  (

hi,
ya f9 its working good.actually i was fresher.i was not given any training in the company.i have to learn from net and should train myself.so i was asking u freqent.

thanq for ur timely help with good codes.

hi,
i have analysed the output of the code.but its not comparing correctly.
if X_RAMB18E1 module is taken in filename1 for the first occurances we have the instance like

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_u

if X_RAMB18E1 module is taken in filename2 for the first occurances we have the instance like

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_l

so arrangement of modules occurances is different from two files.
but comparision should not done like this.it should be done among the same instances only.
That isX_RAMB18E1 module is taken in filename1 has an instance

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_l

it should be compared with X_RAMB18E1 module is taken in filename2 has an instance only like

\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_l

if ok means we can compare otherwise i have to search the file upto search criteria is find
But files have same no of modules and instances.but not comparing correctly.
we have to take one instance from file1 and find the occurance in another file and compare.
i was attaching all file1 file2 and code.pls run once and see.
in short problem.
Take one instance from X_RAMB18E1 from file1 and find its existence in second file2 if found compare that modules only.

that is X_RAMB18E1 module should be compared only if they have same instances .

my code also generate instances also.once you please run the code and give me solution.please help this was the final requirement.

my perl project will get completed.
upto now code is
1.read files
2.extracted the code
before comparison we have to do comparison of instances if ok means next comparison
(but every module instance in one file has compulsarily one instance in other file
3.comparision
instance means like this
\U_eth_aggregator_tb/eth_aggregator/core_0/client_side_FIFO0/tx_fifo_i/ramgen_u
i was able to get them by inst_name1 inst_name2 .

#!/usr/bin/perl
use strict;
use warnings; 
my $filename1='/home/david/Programming/Perl/data/filename1.txt';
my $filename2='/home/david/Programming/Perl/data/filename2.txt';
my $modul='X_RAMB18E1';
print " --------------------------------File1: $filename1\t\t File2:$filename2    -------------------------------------\n\n"; 
print "Module selected for comparision $modul\n\n";
my $string1 = readfile( $filename1);
my $string2 = readfile( $filename2); 
$string1 =~ s/[[:cntrl:]]//gm; 
$string2 =~ s/[[:cntrl:]]//gm; 

$string1 =~ /($modul\s#\(.*\);)/gs;
my $instancesfrom1 = $1;
undef $string1;
my @instances_1 = $instancesfrom1 =~ /$modul #\(([^;]*)\);/g;
my $instancescount1 = @instances_1;
print "Found $instancescount1 instances of $modul in the $filename1\n";

$string2 =~ /($modul\s#\(.*\);)/gs;
my $instancesfrom2 = $1;
undef $string2;
my @instances_2 = $instancesfrom2 =~ /$modul #\(([^;]*)\);/g;
my $instancescount2 = @instances_2;
print "Found $instancescount2 instances of $modul in the $filename2\n";

die "$filename1 doesn't have same number of instances of $modul as $filename2!"
    unless $instancescount1 == $instancescount2;
my $i;

my %instance_index_1 = build_index_hash(\@instances_1);
my %instance_index_2 = build_index_hash(\@instances_2);

foreach(sort keys %instance_index_1){
    if (exists $instance_index_2{$_}){
        print "Comparing Instance $_------\n";
        compareinstances($instance_index_1{$_}, $instance_index_2{$_});
    }
    else{
        print "Instance $_ not found in second file.------\n"
    }
}

sub build_index_hash{
    my @arr = @{$_[0]}; #dereference passed parameter
    my %h;
    my $i;
    foreach (@arr){
        $_ =~ m/\)\s*\)\s*(.*)\s*\(\s*\./;
        $h{$1} = $i++;
    }
    return %h;
}

sub compareinstances
{
    my $x = shift @_;
    my $y = shift @_;
    my $modcodefrom1 = $instances_1[$x];
    my $modcodefrom2 = $instances_2[$y];
    my $inst_name1;
    if($modcodefrom1 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
        $inst_name1 = $1;
    }
    print "instance name from 1 is $inst_name1\n";
   
    my $inst_name2;
        if($modcodefrom2 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
            $inst_name2 = $1;
        }
    print "instance name from 2 is $inst_name2\n ";
   my @codes1 = split /\,/,  $modcodefrom1;
   my @codes2 = split /\,/,  $modcodefrom2;
   
    print "\t\t****************THE DIFFERENCES IN THE FILES ARE AS FOLLOWS****************\n\n\n";
    printf "\t\t%-45s \t\t\t%s\n\n\n", $filename1, $filename2;
    my $i = 0;
    foreach ( @codes1) {
        unless ( $codes1[$i] eq $codes2[$i]) {
        printf "%-s IS NOT SAME AS %s\n\n", $codes1[$i], $codes2[$i];
        }
    $i++;
    }
}

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

Hi,
First of all i was thankful to u for your timely help by code.
The code work good.problem is it is working upto 68 modules and not working for 21 modules.
what i have observed in those 68 modules is lines arrangement in modules are same(position of lines).so codes eq codes[j] works.
for example first line in module of file1 has sham and first line in module of file2 has sham .then code works excellently.
otherwise problem.

so i think i have to do other than line wise comparision.
the common property of all the modules lines is
FOR EX .LOC ( "SLICE_X53Y152" )
STARTS WITH DOT AND ENDS WITH CLOSE BRACE.
THE COMPARISION I HAVE TO DO IS
1.)instances comparison if ok means comparision(already you done for me yesterday)

2.)now code comparison i have to add another level of comparision

for this the way i have to do is if we take above example

1.take content in between DOT and OPENING BRACE in file1, module(we get loc)

2.)take content form 1(loc) as search parameter and find the content present in file2 module

3.)if found take the content from dot to closing brace (.LOC ( "SLICE_X53Y152" )form two modules of two files and compare

like wise i have to do upto the end of module. upto number of occurances

i think my req was finished.but one more please give me solution.
i was learning a lot from u.

i was attaching files and the code is same as before but modul name is X_RAMD32

#!/usr/bin/perl
use strict;
use warnings; 

my $filename1='/home/david/Programming/Perl/data/filename1.txt';
my $filename2='/home/david/Programming/Perl/data/filename2.txt';
my $modul='X_RAMD32';
print " --------------------------------File1: $filename1\t\t File2:$filename2    -------------------------------------\n\n"; 
print "Module selected for comparision $modul\n\n";
my $string1 = readfile( $filename1);
my $string2 = readfile( $filename2); 
$string1 =~ s/[[:cntrl:]]//gm; 
$string2 =~ s/[[:cntrl:]]//gm; 

$string1 =~ /($modul\s#\(.*\);)/gs;
my $instancesfrom1 = $1;
undef $string1;
my @instances_1 = $instancesfrom1 =~ /$modul #\(([^;]*)\);/g;
my $instancescount1 = @instances_1;
print "Found $instancescount1 instances of $modul in the $filename1\n";

$string2 =~ /($modul\s#\(.*\);)/gs;
my $instancesfrom2 = $1;
undef $string2;
my @instances_2 = $instancesfrom2 =~ /$modul #\(([^;]*)\);/g;
my $instancescount2 = @instances_2;
print "Found $instancescount2 instances of $modul in the $filename2\n";

#die "$filename1 doesn't have same number of instances of $modul as $filename2!"
 #   unless $instancescount1 == $instancescount2;
my $i=1;
my %instance_index_1 = buildindexhash(\@instances_1);
my %instance_index_2 = buildindexhash(\@instances_2);

foreach(sort keys %instance_index_1){
    if (exists $instance_index_2{$_}){
        print "Comparing $i Instance $_------\n";
        compareinstances($instance_index_1{$_}, $instance_index_2{$_});
    }
    else{
        print "Instance $_ not found in second file.------\n";
    }
$i++;
}

sub buildindexhash{
    my @arr = @{$_[0]}; 
    my %h;
    my $i;
    foreach (@arr){
        $_ =~ m/\)\s*\)\s*(.*)\s*\(\s*\./;
        $h{$1} = $i++;
    }
    return %h;
}

sub compareinstances
{
    my $x = shift @_;
    my $y = shift @_;
    my $modcodefrom1 = $instances_1[$x];
    my $modcodefrom2 = $instances_2[$y];
    my $inst_name1;
    if($modcodefrom1 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
        $inst_name1 = $1;
    }
    print "instance name of $modul from file1 $filename1 is $inst_name1\n";
   
    my $inst_name2;
        if($modcodefrom2 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
            $inst_name2 = $1;
        }
    print "instance name of $modul from file2 $filename2 is $inst_name1\n ";
   my @codes1 = split /\,/,  $modcodefrom1;
   my @codes2 = split /\,/,  $modcodefrom2;
   
    print "\t\t****************THE DIFFERENCES IN THE FILES ARE AS FOLLOWS****************\n\n\n";
   
    printf "\t\t%-45s \t\t\t%s\n\n\n", $filename1, $filename2;

    foreach (@codes1){
    if ( m/
        (         #capture following to $1
         (        #capture following to $2
         \.       #dot
         [^(]+    #one or more characters excepting (
        )         #end of capture group $2
         \s*      #possibly some spaces or newlines
         \(       #followed by open (
           [^)]*? #possibly some characters excepting )
           \)     #followed by close )
         )        #end of capture group $1
          /x ){   #end of match condition. x means ignore spaces and allow comments
        my $all_code_1 = $1;
        my $lkup_cd1 = $2;
        my $code2compare = lookup_code2($lkup_cd1, \@codes2);
        unless ( $all_code_1 eq $code2compare) {
        printf "%-s IS NOT SAME AS %s\n\n", $all_code_1, $code2compare;
        }
    }
    }
}

sub lookup_code2{
    my $lkup = shift @_;
    #print "Attempting to match $lkup\n";
    my @cds2 = @{shift @_};
    foreach (@cds2){
    s/^\s+//; #remove leading spaces
    s/\s+$//; #remove trailing spaces
    if ( m/^(\Q$lkup(\E.+?\))/ ) { #\Q means escape non-word characters (such as dot) until \E
        #print "Returning $1\n";
        return $1;
    }
    }
    return "No match found in codes 2";
}

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

Hi,
Thank u for ur code.i was checking it for alla my 95 modules.it took some time for me to say about the working condition.anyway you are the great help for me.

what i have to do to learn perl.any tutorials there or any methods you suggest me to learn.if so pls send me the links of where i have to learn the perl

I'm glad it works. I bought Beginning Perl by Simon Cozens 5 years ago and have read it all through. I have referred to it often. Now it is available for free online. Learning Perl, by Randal Schwartz and others is good too, but not free.

A good source of documentation and tutorials would be perl.org. When I'm stuck I google perl plus a few key words. Often the answer turns up on stackoverflow.com, perl.org, perlmonks.org, about.perl.com and of course, daniweb.com.

Hi,
I have anotherr problem.Actually we are extracting the content of module between hash

paranthesis and ending with closing paranthesis and semicolan.but actually when i was

changing the RE to extact the code upto two closing paranthesis(two closing brackets)

getting error.i did it by simply removing semicolan in RE and replaced with slash bracket.
but error was coming

in short each module has the code
as follows

X_RAMB18E1 #(
                                    
---------------------
---------------------
))
-----------
);

now i want to extract code above double brackts in both files and compare them and print the diff.
remaining everything is same i think i have to change the RE.

remaing instance comp etc same but the thing is i have to extract the code upto first

occurance of double closing paranthesis

In the two files to identify i wrote END at the place of double paranthesi

But major twist is we are doing instance comparision know

but that line is below double paranthesis(or bracket)so i was getting error.

so i want instance based comparision but comparison of parameters should be abovr double

paranthesis only

plese try to help me

hi,i have solved the problem.
i was able to write RE and made it to work
yesterday i read some of the articles you have said and solved this

Hi,
I have another problem.the code is working fine.
But in the differences i dont want differences of LOC parameters.
For example
.LOC ( "MMCM_ADV_X0Y0" ) IS NOT SAME AS .LOC ( "MMCM_ADV_X0Y5" )
should be eliminated.like wise each time module diff has parameters starting with .LOC("--------")
should not be eliminated
But i was trying with if loop at $lkup_cd1 notequal to .LOC entering into the loop otherwise doing
nothing in the loop.But i was unable to do it.

so when we are checking for the occurances (which u did for me two days before)

and comparing parameter wise we should eliminate parameters starting with .LOC

(thatis we are taking content between dot and first bracket we get LOC know
at that time we should not call function to show differences for remaining we shouls do
like that.)


so please try to help me

The trailing space in $lkup_cd1 spoils the test for '.LOC'. I changed only the following subroutine.

sub compareinstances
{
    my $x = shift @_;
    my $y = shift @_;
    my $modcodefrom1 = $instances_1[$x];
    my $modcodefrom2 = $instances_2[$y];
    my $inst_name1;
    if($modcodefrom1 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
        $inst_name1 = $1;
    }
    print "instance name of $modul from file1 $filename1 is $inst_name1\n";
   
    my $inst_name2;
        if($modcodefrom2 =~ m/\)\s*\)\s*(.*)\s*\(\s*\./) {
            $inst_name2 = $1;
        }
    print "instance name of $modul from file2 $filename2 is $inst_name1\n ";
   my @codes1 = split /\,/,  $modcodefrom1;
   my @codes2 = split /\,/,  $modcodefrom2;
   
    print "\t\t****************THE DIFFERENCES IN THE FILES ARE AS FOLLOWS****************\n\n\n";
   
    printf "\t\t%-45s \t\t\t%s\n\n\n", $filename1, $filename2;

    foreach (@codes1){
    if ( m/
        (         #capture following to $1
         (        #capture following to $2
         \.       #dot
         [^(]+    #one or more characters excepting (
        )         #end of capture group $2
         \s*      #possibly some spaces or newlines
         \(       #followed by open (
           [^)]*? #possibly some characters excepting )
           \)     #followed by close )
         )        #end of capture group $1
          /x ){   #end of match condition. x means ignore spaces and allow comments
        my $all_code_1 = $1;
        my $lkup_cd1 = $2;
        
        #The problem was $lkup_cd1 often has a trailing space
        #So in the following condition we must test if equal to '.LOC ' with trailing space
        next if ( $lkup_cd1 eq '.LOC' or $lkup_cd1 eq '.LOC '); #Skip to next iteration of loop
        
        #print "Look up $lkup_cd1\n"; #I print here for testing. May want to comment it out.
        
        my $code2compare = lookup_code2($lkup_cd1, \@codes2);
        
        unless ( $all_code_1 eq $code2compare) {
            printf "%-s IS NOT SAME AS %s\n\n", $all_code_1, $code2compare;
        }
    }
    }
}

hi,thank u for ur great help for solving me with ur codes.the project is completed

commented: Thanks for attaching sample files, explaining progress, and marking it solved. +2
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.