J
JRoot
Below I posted my program in it's entirity and I hope that is within
the guidelines ...
The program works perectly but it seems to run slower than I had
expected based on other perl programs I've authored with much more
data involved.
I've been through the faq's and every web site that focuses on perl
and to be honest, I'm overwhelmed by the number of ways it's possible
to use perl so I'm asking if anyone could just look over this program
and see if it is obvious where the overhead lies so I can remove the
baggage and speed it up a bit. It runs in about 3-5 seconds on a 1 ghz
machine but my gut tells me it could be faster or more efficient if
you will. I'm not asking anyone to do my work for me ... just for a
pointer from anyone that deals with arrays and hashes a lot.
The roadmap is ...
I create an array from a file (one word per line)
I create a hash from a 2nd file, combining duplicate key words and
assign the duplicate quantity as the value. A key-val pair would look
like ... net_name 5
I iterate the array and search the hash keys to find a match and then
report the key and val to different reports depending on the val
(quantity) which is either 0 (not found) 1 (single occurance) or
multiple which need to be verified.
I suspect I've arrayed and hashed one too many times when it could
have been done in a more simple manner.
Any help is appreciated -- thank you
snip<------ cut here -------->snip
#!/app/util/perl/bin/perl -w
BEGIN { push(@INC, "/app/util/perl5.6.1/lib/5.6.1") }
use strict;
my @nets = ();
my %count = ();
my %list = ();
my ($net, $x, $y, $netName, $side, $junk, $line, $checkHashVal);
my ($sortedNet, $tpList, $key, $val, $list, $checkHashKey, $found);
my ($oneArr, $verifyArr, $zeroArr, $line2Push);
my $lineCnt = 0;
my @tpList = ();
my @sortedNets = ();
my @zeroArr = ();
my @oneArr = ();
my @verifyArr = ();
my $cnt = 0;
print "\n\n... Working .... \n\n";
open (TL, "tp_list") || die "Can't open tp_list for reading: $!";
while(<TL>){
chomp($_);
push(@tpList, $_);
}
close(TL);
open (TC, "testpoint_chart") || die "Can't open testpoint_chart for
reading: $!";
while(<TC>){
$line = $_;
++$lineCnt;
if($lineCnt > 9){
($x, $y, $netName, $side, $junk) = split(' ', $line, 5);
if($side eq "Top" || $side eq "Bottom"){
push(@nets, $netName);
}
}
}
close(TC);
@sortedNets = @nets;
foreach $sortedNet(@sortedNets) {
$count{$sortedNet} = ++$count{$sortedNet};
}
foreach $sortedNet (keys %count) {
($key, $val) = ($sortedNet, $count{$sortedNet});
$list{$key} = $val;
}
foreach $tpList (@tpList) {
$found = "no";
++$cnt;
foreach $key (keys %list) {
if ($key eq $tpList) {
$found = "yes";
$line2Push = "ARR: $key -- HASHKEY: $tpList VAL:
$list{$tpList}\n";
if($list{$tpList} eq "1"){
push(@oneArr, $line2Push);
}
elsif($list{$tpList} ne "1"){
push(@verifyArr, $line2Push);
}
last;
}
}
if($found eq "no"){
push(@zeroArr, $tpList);
}
}
print "\n===== ONES =====\n";
print "------------------\n";
foreach $oneArr(@oneArr){print "ONES: $oneArr";}
print "\n===== VERIFY =====\n";
print "--------------------\n";
foreach $verifyArr(@verifyArr){print "VERIFY: $verifyArr";}
print "\n===== ZERO =====\n";
print "--------------------\n";
foreach $zeroArr(@zeroArr){print "ZERO: $zeroArr\n";}
print " ... D O N e ... \n\n";
the guidelines ...
The program works perectly but it seems to run slower than I had
expected based on other perl programs I've authored with much more
data involved.
I've been through the faq's and every web site that focuses on perl
and to be honest, I'm overwhelmed by the number of ways it's possible
to use perl so I'm asking if anyone could just look over this program
and see if it is obvious where the overhead lies so I can remove the
baggage and speed it up a bit. It runs in about 3-5 seconds on a 1 ghz
machine but my gut tells me it could be faster or more efficient if
you will. I'm not asking anyone to do my work for me ... just for a
pointer from anyone that deals with arrays and hashes a lot.
The roadmap is ...
I create an array from a file (one word per line)
I create a hash from a 2nd file, combining duplicate key words and
assign the duplicate quantity as the value. A key-val pair would look
like ... net_name 5
I iterate the array and search the hash keys to find a match and then
report the key and val to different reports depending on the val
(quantity) which is either 0 (not found) 1 (single occurance) or
multiple which need to be verified.
I suspect I've arrayed and hashed one too many times when it could
have been done in a more simple manner.
Any help is appreciated -- thank you
snip<------ cut here -------->snip
#!/app/util/perl/bin/perl -w
BEGIN { push(@INC, "/app/util/perl5.6.1/lib/5.6.1") }
use strict;
my @nets = ();
my %count = ();
my %list = ();
my ($net, $x, $y, $netName, $side, $junk, $line, $checkHashVal);
my ($sortedNet, $tpList, $key, $val, $list, $checkHashKey, $found);
my ($oneArr, $verifyArr, $zeroArr, $line2Push);
my $lineCnt = 0;
my @tpList = ();
my @sortedNets = ();
my @zeroArr = ();
my @oneArr = ();
my @verifyArr = ();
my $cnt = 0;
print "\n\n... Working .... \n\n";
open (TL, "tp_list") || die "Can't open tp_list for reading: $!";
while(<TL>){
chomp($_);
push(@tpList, $_);
}
close(TL);
open (TC, "testpoint_chart") || die "Can't open testpoint_chart for
reading: $!";
while(<TC>){
$line = $_;
++$lineCnt;
if($lineCnt > 9){
($x, $y, $netName, $side, $junk) = split(' ', $line, 5);
if($side eq "Top" || $side eq "Bottom"){
push(@nets, $netName);
}
}
}
close(TC);
@sortedNets = @nets;
foreach $sortedNet(@sortedNets) {
$count{$sortedNet} = ++$count{$sortedNet};
}
foreach $sortedNet (keys %count) {
($key, $val) = ($sortedNet, $count{$sortedNet});
$list{$key} = $val;
}
foreach $tpList (@tpList) {
$found = "no";
++$cnt;
foreach $key (keys %list) {
if ($key eq $tpList) {
$found = "yes";
$line2Push = "ARR: $key -- HASHKEY: $tpList VAL:
$list{$tpList}\n";
if($list{$tpList} eq "1"){
push(@oneArr, $line2Push);
}
elsif($list{$tpList} ne "1"){
push(@verifyArr, $line2Push);
}
last;
}
}
if($found eq "no"){
push(@zeroArr, $tpList);
}
}
print "\n===== ONES =====\n";
print "------------------\n";
foreach $oneArr(@oneArr){print "ONES: $oneArr";}
print "\n===== VERIFY =====\n";
print "--------------------\n";
foreach $verifyArr(@verifyArr){print "VERIFY: $verifyArr";}
print "\n===== ZERO =====\n";
print "--------------------\n";
foreach $zeroArr(@zeroArr){print "ZERO: $zeroArr\n";}
print " ... D O N e ... \n\n";