"Baker, Lauren" wrote:
>
> How do I update one field in a hash based on a selection
> of two others?
>
> I have data like this (there are 35 total):
> $flam_table{5} = {ctype => "Capacitor",
> ptype => "Epoxy",
> cc => "15", mass => 0, rating => "UL94V-0"};
> $flam_table{6} = {ctype => "Capacitor",
> ptype => "Metalized Paper",
> cc => "15", mass => 0, rating => "UL94V-0"};
> $flam_table{7} = {ctype => "Inductor",
> ptype => "Thermoplastic",
> cc => "18", mass => 0, rating => "UL94V-0"};
>
> I then have a list of items, where I can figure out the
> "cc" and "ptype" values. I then want to select the correct
> entry and update the mass entry (the list of items has a quantity
> and unit mass - so I multiply and add to the appropriate
> entry). After going thru the list of items, I then spit out
> all these 35 entries into a spreadsheet, one field per
> column.
I don't understand. Are you sure you don't want an array instead of a hash
for $flam_table. I also don't really see an explicit question. This code
will assume it's an array rather than a hash and find the item (given cc
and ptype) that matches:
use strict;
my @flam_table;
$flam_table[5] = {ctype => "Capacitor", ptype => "Epoxy",
cc => "15", mass => 0, rating => "UL94V-0"};
$flam_table[6] = {ctype => "Capacitor", ptype => "Metalized Paper",
cc => "15", mass => 0, rating => "UL94V-0"};
$flam_table[7] = {ctype => "Inductor", ptype => "Thermoplastic",
cc => "18", mass => 0, rating => "UL94V-0"};
foreach (@flam_table) {
next if not defined $_;
if ($_->{cc} == 15 and lc $_->{ptype} eq "metalized paper") {
print "Found my item\n";
}
}
__END__
Please try a more explicit question showing all inputs and expected results.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles http://www.wgn.net/~dbe/
/ ) /--< o // // Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_ http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users