I am trying to compare some data between two files.
First I open a file (brd_sym_pn.txt) with data extracted from a database and pull the reference designator($RefDes), part number ($Pnum) and package type ($Pkg_Type).
Then I open another file (sym_text_latest.txt) and extract/assign the part number ($LogPnum) and package type ($LogPkg_Type).
I am trying to compare the $Pnum and $Pkg_Type for each $ RefDes between brd_sym_pn.txt and sym_text_latest.txt, reporting back if the $Pnum/ $pkg_Type does/does notmatches the $LogPnum/$LogPkg_Type assignment in sym_text_latest.txt.
It seems that I have too many loops and should be cycling through each reference designator or line of brd_sym_pn.txt.
I have tried to make this work for about 3-4 days and desperately need some help.
brd_sym_pn.txt
Begin
J2 12-0259-01 HDR-1X28-100-FLK-VT
P1 12-0258-01 HDR-2X12-118-VT end
J1 12-0259-01 HDR-1X2-100-FLK-VT
P2 12-0257-01 HDR-2X7-118-VT
MTG4 MTG_250_H115 MTG_250_H115
MTG5 MTG_250_H115 MTG_250_H115
P3 12-0255-01 RECPT-2X7-118-VT
MTG3 MTG_250_H115 MTG_250_H115
P4 12-0255-01 RECPT-2X7-118-VT
MTG2 MTG_250_H115 MTG_250_H115
MTG1 MTG_250_H115 MTG_250_H115
END
sym_text_latest.txt
Begin
Part number type mfg. P/n description pkg_type height mm > mil notes
12-0255-01 CON 44769-1403 "CONN,REC,14 PIN,THOLE,0.118 SPACE,VERT,RECPT-2X7-118-VT" RECPT-2X7-118-VT 13.6 535.432 new part number release
12-0256-01 CON 44769-1203 "CONN,REC,12 PIN,THOLE,0.118 SPACE,VERT,RECPT-2X6-118-VT" RECPT-2X6-118-VT 13.6 535.432 new part number release
12-0257-01 CON 43045-1414 "CONN,HDR,14 PIN,THOLE,0.118 SPACE,VERT,HDR-2X7-118-VT" HDR-2X7-118-VT 9.9 389.763 new part number release
12-0258-01 CON 43045-1214 "CONN,HDR,12 PIN,THOLE,0.118 SPACE,VERT,HDR-2X6-118-VT" HDR-2X6-118-VT 9.9 389.763 new part number release
12-0259-01 CON 22-29-2021 "CONN,HDR,2 PIN,THOLE,0.100 SPACE,VERT,HDR-1X2-100-FLK-VT" HDR-1X2-100-FLK-VT 11.7 460.629 new part number release
END
#Delete current temp_sym_pn.txt if exists.
`del temp_ref_list.txt`;
{
open(brdpartlog, "brd_sym_pn.txt") || die("failed to open br
+d_sym_pn.txt");
print "\n";
while($line = <brdpartlog>)
{
@fields = split(/\t/,$line);
# if($fields[1] eq $Pnum)
{
our $RdesPnPkg = "$fields[0]\t$fields[1]\t$fields[2]
+";
our $RdesPn = "\"$fields[0]\"\t\=>\t\"$fields[1]\",
+";
our $BrdPnPkg = "$fields[1]\t$fields[2]";
our $RefDes = "$fields[0]";
our $Pnum = "$fields[1]";
our $Pkg_Type = "$fields[2]";
}
%hash_ref_pn = ($RefDes, $Pnum);
my @k = keys %hash_ref_pn;
my @v = values %hash_ref_pn;
print $k[0] ,"\t", $v[0], "\n";
# I thought this would assign $k to key in %hash_
+ref_pn
# and would print each Key (reference designator)
$k[0] = $Rf_Ds;
print $Rf_Ds;
# I thought this would assign $v to key in %hash_
+ref_pn
# and would print each Key (Part_Number)
$v = $Part_Number;
print $Part_Number;
#prints value (12-0259-01) of key J2
#print ($hash_ref_pn{J2});
#counts the number of keys included in %hash_ref
+_pn
my $count = keys %hash_ref_pn;
#print $count;
#print "\n";
#creates a string that resembles an associative hash
#of reference designators
#example: "J2" => "12-0259-01", "P1" => "12
+-0258-01",
#Prints each reference designators on one line.
#@RdesList=();
#@RdesList=($RefDes);
open(Ref_List, ">>temp_ref_hash.txt");
print Ref_List "$RdesPn\t";
close(Ref_List);
}
open(Ref_List, "temp_ref_hash.txt");
@lines = <Ref_List>;
$lines = $Pnum;
close(Ref_List);
#print @lines;
my %hash_ref_pn = <Ref_List>;
print ($hash_ref_pn{"J1"});
print "\n";
#print ("xxxxxxxxxx\n" x 3);
print "$Pnum was the last assigned \$Pnum";
#Type out temp_ref_list.txt to screen, DOES NOT WORK???
#`Type c:\\work\\academy_x\\log_pn_check\\temp_ref_list.txt`;
#exit;
print "\n";
open(brdpartlog, "brd_sym_pn.txt") || die("failed to open br
+d_sym_pn.txt");
print "\n";
while($line = <brdpartlog>)
{
@fields = split(/\t/,$line);
if($fields[1] eq $Pnum)
{
our $RdesPnPkg = "$fields[0]\t$fields[1]\t$fields[2]
+";
our $BrdPnPkg = "$fields[1]\t$fields[2]";
our $RefDes = "$fields[0]";
our $Pnum = "$fields[1]";
if($BrdPnPkg eq $LogPnPkg)
{
print("$RefDes\t$BrdPnPkg is the correct Allegro footp
+rint.\n");
}
else
{
print("$RefDes\t$BrdPnPkg should be using $LogPkg_Type
+\n");
}
}
}
open(partlog, "sym_text_latest.txt") || die("failed to open sym_
+text_latest.txt");
while($line = <partlog>)
{
@fields = split(/\t/,$line);
if($fields[0] eq $Pnum)
{
our $LogPnPkg = "$fields[0]\t$fields[4]";
our $LogPnum = "$fields[0]";
our $LogPkg_Type = "$fields[4]";
}
}
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.