L
lynn
Hi All,
I am tring to generate a HoH's without using duplicate code. (see script)
Can someone help me do the same thing without the duplicate code
Thanks!!
Lynn
use strict;
use warnings;
use Data:
umper;
my %product = ();
while (<DATA>) {
my ( $family, $hour ) = split(/,/);
for ($family) {
if (/NX/) {
$product{'NX'}{'hour'} += $hour;
$product{'NX'}{'count'}++;
} # do something
elsif (/UNIGRAPHICS_NX/) {
$product{'NX'}{'hour'} += $hour;
$product{'NX'}{'count'}++;
}
elsif (/TC_ENGR-IMAN/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/SOLID_EDGE/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/WEBTOOLS/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/TC_COMMUNITY/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
else {
$product{'OTHER'}{'hour'} += $hour;
$product{'OTHER'}{'count'}++;
} # default
}
}
print Dumper( \%product );
__DATA__
NX,4.098
UNIGRAPHICS_NX,2.009
WEBTOOLS,.98
TC_ENGR-IMAN,2.09
FEMAP,0.54
SOLID_EDGE,1.03
TC_COMMUNITY,9.02
FEMAP,.81
TC_ENG-META,1.07
NX,1.308
TC_ENGR-IMAN,4.39
I am tring to generate a HoH's without using duplicate code. (see script)
Can someone help me do the same thing without the duplicate code
Thanks!!
Lynn
use strict;
use warnings;
use Data:
my %product = ();
while (<DATA>) {
my ( $family, $hour ) = split(/,/);
for ($family) {
if (/NX/) {
$product{'NX'}{'hour'} += $hour;
$product{'NX'}{'count'}++;
} # do something
elsif (/UNIGRAPHICS_NX/) {
$product{'NX'}{'hour'} += $hour;
$product{'NX'}{'count'}++;
}
elsif (/TC_ENGR-IMAN/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/SOLID_EDGE/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/WEBTOOLS/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
elsif (/TC_COMMUNITY/) {
$product{$family}{'hour'} += $hour;
$product{$family}{'count'}++;
}
else {
$product{'OTHER'}{'hour'} += $hour;
$product{'OTHER'}{'count'}++;
} # default
}
}
print Dumper( \%product );
__DATA__
NX,4.098
UNIGRAPHICS_NX,2.009
WEBTOOLS,.98
TC_ENGR-IMAN,2.09
FEMAP,0.54
SOLID_EDGE,1.03
TC_COMMUNITY,9.02
FEMAP,.81
TC_ENG-META,1.07
NX,1.308
TC_ENGR-IMAN,4.39