I have the following data that is read into a hash
==============================================
507: quantity=1.0000 ,description=THERMOWELL ,tags= TW-3,partnum=2202579000
658: quantity=1.0000 ,description=FLOWMETER ,tags=FE-1/FT-1 ,partnum=2901675000
557: quantity=1.0000 ,description=THERMOWELL ,tags= TW-1 TW-2,partnum=2202579000
593: quantity=3.0000 ,description=THERMOWELL ,tags= ,partnum=2202579000
==============================================
by
===============================================
foreach (@file) {
chomp;
s/^(.*?):\s*//;
$who=$1;
$rec = {};
$HoH{$who}=$rec;
for $field (split(/,/)) {
($key,$value) = split /=/, $field;
$rec->{$key} =$value;
}
}
=================================================
I ultimately need to combine the hash down to a single key that has the combined tags of all the same partnum.
I've tried sorting the hash via
==================================================
my @partgroups = sort {lc($HoH{$a}{partnum}) cmp lc($HoH{$b}{partnum}) || $HoH{$a}{partnum} <=> $HoH{$b}{partnum}} keys %HoH;
==================================================
and
============================================
my $i=0;
my $flag = 0;
my @combine=();
for $i (1 .. $#partgroups) {
for my $k1 (keys %HoH) {
if (lc($HoH{$partgroups[$i]}{partnum}) eq $HoH{$k1}{partnum} && lc($HoH{$partgroups[($i-1)]}{partnum}) eq $HoH{$k1}{partnum}) {
$flag =1;
push @combine, $k1;
}
if ($flag == 1) {
push @combine,$k1;
$flag =0;
}
}
}
====================================================
Without any success. Any thoughts on the best way to go about this?
==============================================
507: quantity=1.0000 ,description=THERMOWELL ,tags= TW-3,partnum=2202579000
658: quantity=1.0000 ,description=FLOWMETER ,tags=FE-1/FT-1 ,partnum=2901675000
557: quantity=1.0000 ,description=THERMOWELL ,tags= TW-1 TW-2,partnum=2202579000
593: quantity=3.0000 ,description=THERMOWELL ,tags= ,partnum=2202579000
==============================================
by
===============================================
foreach (@file) {
chomp;
s/^(.*?):\s*//;
$who=$1;
$rec = {};
$HoH{$who}=$rec;
for $field (split(/,/)) {
($key,$value) = split /=/, $field;
$rec->{$key} =$value;
}
}
=================================================
I ultimately need to combine the hash down to a single key that has the combined tags of all the same partnum.
I've tried sorting the hash via
==================================================
my @partgroups = sort {lc($HoH{$a}{partnum}) cmp lc($HoH{$b}{partnum}) || $HoH{$a}{partnum} <=> $HoH{$b}{partnum}} keys %HoH;
==================================================
and
============================================
my $i=0;
my $flag = 0;
my @combine=();
for $i (1 .. $#partgroups) {
for my $k1 (keys %HoH) {
if (lc($HoH{$partgroups[$i]}{partnum}) eq $HoH{$k1}{partnum} && lc($HoH{$partgroups[($i-1)]}{partnum}) eq $HoH{$k1}{partnum}) {
$flag =1;
push @combine, $k1;
}
if ($flag == 1) {
push @combine,$k1;
$flag =0;
}
}
}
====================================================
Without any success. Any thoughts on the best way to go about this?