P
perl_newbie
My problem is that I would like to compare 2 hash of hashes. I got a
gold standard; which is my hierarchy, and a list of cells in the cad
tree that were copied with erroneous cell names that I would like to
clean up. The program below works for a $cadcell name but not library
and I would like it to be more robust. I like to compare the $hie_cell
in my gold standard exists in my cad tree and the library associated
with my $hie_cell->$hie_lib in the gold standard is also the same in my
cad tree cadcell->$cadlib. Then anything that is not found in the gold
standard is then push to a file.
here in my last sub routine, I need to have additional checks for the
library too and not the cell name alone but need help and any help will
be very much appreciated.
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{
my ($cadlib,$cadcell)=($1,$2);
#$cadrec->{$cadcell}->{$cadlib}=1;
#here I need to check for libraries too!
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
print BCELL "$cadcell\n";
}
}
}
}
input files below:
Gold standard
Lib0 cell1
Lib1 cell2
Lib3 cell3
Lib4 cell1 --note this would be a warning(my comment)
Lib1 cell4
Cad tree hierarchy
Lib0 cell1
Lib1 cell2
Lib1 cell2A --note is junk; bad name; to be push to a file
Lib3 cell3
Lib4 cell3 --note this is also junk; copied in the wrong lib
Lib4 cell1
Lib1 cell4
My code only flags the cells that are not found with in the hierarchy
but I also need to check the libraries associated with the $hiecell.
Can you help?
-------my code---------------------------------
#!usr/bin/perl -w
use strict;
# use Getopt::Long;
my $show_file={};
my $hierec={};
my $cadrec={};
my $hie_cell={};
my $hie_lib={};
my $cadcell={};
my $cadlib={};
my @cell=();
#-------------------------------------------------------------
#getting the arguments of the files to be read by checker
if ($#ARGV != 1 )
{
print "Requires these 2 files <showhi> <compr_list>\n";
exit;
}
my $list1=$ARGV[0];
my $list2=$ARGV[1];
open(L1,"<$list1") || die "cannot open first file";
open(L2,"<$list2") || die "cannot open second file";
#----------------------------------------------------
#opening files for write in user's dir
my $dir = `pwd`;
chop($dir);
my $efile = $dir."/rec.err";
open(ERR ,">$efile") || die "cannot open new error file\n";
my $gfile = $dir."/rec.gd_cll";
open(GCELL,">$gfile") || die "cannot open the Good Cell file\n";
my $dfile = $dir."/rec.dmp";
open(BCELL,">$dfile") || die "cannot open Bad Cell file\n";
###########################
# let's find the bad cells#
###########################
#-------------------------------------------------------
#assigning the items of interest in a hash
# hash key key
# rec -> cell -> lib
while(<L1>)
{
$show_file=$_;
if ($show_file=~/^\S+\s+\d\.\s+(\S+)\s+(\S+)/ ||
$show_file=~/^\d\.\s+(\S+)\s+(\S+)/)
{
my ( $hie_cell, $hie_lib)= ($2, $1);
$hierec->{$hie_cell}->{$hie_lib}=1;
#making the cell & lib to exist as a hash later to be used as error
finder
}
}
#-----------------------------------------------
# place the lib keys in an array variable for easier readability,
#&error_check;
sub error_check
{
foreach my $hie_cell (keys %$hierec)
{
my @lib = sort keys %{ $hierec->{ $hie_cell } };
if (@lib == 1)
{
print "$hie_cell \t(@lib)\n";
print GCELL"$hie_cell (@lib)\n";
}
if( @lib >1 )
{
print ERR "$hie_cell (@lib) - Warning/Error?\n";
}
}
}
#-------------------------------------------------
# only the cells is being checked but need the
# library to be checked too.
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{
my ($cadlib,$cadcell)=($1,$2);
#$cadrec->{$cadcell}->{$cadlib}=1;
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
print BCELL "$cadcell\n";
}
}
}
}
#-------------------------------------------------------------------------------
close(GCELL);
close(BCELL);
close(ERR);
gold standard; which is my hierarchy, and a list of cells in the cad
tree that were copied with erroneous cell names that I would like to
clean up. The program below works for a $cadcell name but not library
and I would like it to be more robust. I like to compare the $hie_cell
in my gold standard exists in my cad tree and the library associated
with my $hie_cell->$hie_lib in the gold standard is also the same in my
cad tree cadcell->$cadlib. Then anything that is not found in the gold
standard is then push to a file.
here in my last sub routine, I need to have additional checks for the
library too and not the cell name alone but need help and any help will
be very much appreciated.
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{
my ($cadlib,$cadcell)=($1,$2);
#$cadrec->{$cadcell}->{$cadlib}=1;
#here I need to check for libraries too!
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
print BCELL "$cadcell\n";
}
}
}
}
input files below:
Gold standard
Lib0 cell1
Lib1 cell2
Lib3 cell3
Lib4 cell1 --note this would be a warning(my comment)
Lib1 cell4
Cad tree hierarchy
Lib0 cell1
Lib1 cell2
Lib1 cell2A --note is junk; bad name; to be push to a file
Lib3 cell3
Lib4 cell3 --note this is also junk; copied in the wrong lib
Lib4 cell1
Lib1 cell4
My code only flags the cells that are not found with in the hierarchy
but I also need to check the libraries associated with the $hiecell.
Can you help?
-------my code---------------------------------
#!usr/bin/perl -w
use strict;
# use Getopt::Long;
my $show_file={};
my $hierec={};
my $cadrec={};
my $hie_cell={};
my $hie_lib={};
my $cadcell={};
my $cadlib={};
my @cell=();
#-------------------------------------------------------------
#getting the arguments of the files to be read by checker
if ($#ARGV != 1 )
{
print "Requires these 2 files <showhi> <compr_list>\n";
exit;
}
my $list1=$ARGV[0];
my $list2=$ARGV[1];
open(L1,"<$list1") || die "cannot open first file";
open(L2,"<$list2") || die "cannot open second file";
#----------------------------------------------------
#opening files for write in user's dir
my $dir = `pwd`;
chop($dir);
my $efile = $dir."/rec.err";
open(ERR ,">$efile") || die "cannot open new error file\n";
my $gfile = $dir."/rec.gd_cll";
open(GCELL,">$gfile") || die "cannot open the Good Cell file\n";
my $dfile = $dir."/rec.dmp";
open(BCELL,">$dfile") || die "cannot open Bad Cell file\n";
###########################
# let's find the bad cells#
###########################
#-------------------------------------------------------
#assigning the items of interest in a hash
# hash key key
# rec -> cell -> lib
while(<L1>)
{
$show_file=$_;
if ($show_file=~/^\S+\s+\d\.\s+(\S+)\s+(\S+)/ ||
$show_file=~/^\d\.\s+(\S+)\s+(\S+)/)
{
my ( $hie_cell, $hie_lib)= ($2, $1);
$hierec->{$hie_cell}->{$hie_lib}=1;
#making the cell & lib to exist as a hash later to be used as error
finder
}
}
#-----------------------------------------------
# place the lib keys in an array variable for easier readability,
#&error_check;
sub error_check
{
foreach my $hie_cell (keys %$hierec)
{
my @lib = sort keys %{ $hierec->{ $hie_cell } };
if (@lib == 1)
{
print "$hie_cell \t(@lib)\n";
print GCELL"$hie_cell (@lib)\n";
}
if( @lib >1 )
{
print ERR "$hie_cell (@lib) - Warning/Error?\n";
}
}
}
#-------------------------------------------------
# only the cells is being checked but need the
# library to be checked too.
&comp_2_cell_list;
sub comp_2_cell_list
{
foreach(<L2>)
{
if(~/^\s?(\S+)\s+(\S+)/)
{
my ($cadlib,$cadcell)=($1,$2);
#$cadrec->{$cadcell}->{$cadlib}=1;
if(! exists($hierec->{$cadcell}))
{
print "list to dump: $cadcell\n";
print BCELL "$cadcell\n";
}
}
}
}
#-------------------------------------------------------------------------------
close(GCELL);
close(BCELL);
close(ERR);