evangraj has asked for the wisdom of the Perl Monks concerning the following question:
I do the same thing for client, and identifier. What I would like to do is build a function which takes as imput a hash of arrays and uses this country array to extract array elements out of the larger array based on the elements of the country array. basically I want to use an array as a filter to build a reduced hash of arrays from a bigger one..... Another bit of code builds an hash of arrays (my first!) and I would like to use the structure produced to filter a larger array witrh the same idea as above. Any suggestions, or condensations, would be appreciated.# ----Build_Country_List ----------------- sub Build_Country_List ($$) { my $j = shift; my $country = shift; print "build country list\n"; $count = 0; if ($j == 0) { print "initial loop\n"; $CountryList[$j] = $country; foreach $tradingcountry (@CountryList) { print "array $j $tradingcountry\n"; } $LengthofCountryList = 1; } else { foreach $tradingcountry (@CountryList) { if ($tradingcountry eq $country) $condition = "FALSE"; $count++; } else { $condition = "TRUE"; } } } if (($condition eq "TRUE") && ($count == 0)) { $LengthofCountryList = scalar(@CountryList); $CountryList[$LengthofCountryList] = $country; } foreach $tradingcountry (@CountryList) { print "country elements $tradingcountry\n"; } $LengthofCountryList = scalar(@CountryList); } # end sub Build_Country_List
Has anyone done this..... where should I start .... I appologize for my novice in advance! Evansub Build_totals_shares_for_sedol_Sell_side($$$) { #$j = shift; my $sedol = shift; my $shares = shift; $condition = ""; my $mySellfirstflag = shift; if ($mySellfirstflag eq "YES") { my $j = 0; } else { my $j = 1;} print "$sedol $shares\n"; $count = 0; if ($j == 0) { %Sellhash = ($sedol => $shares); #print "$Sellhash{key} \n"; foreach $sedolelement (keys %Sellhash) { print "Sell: The $sedolelement has traded\n"; foreach (@{$Sellhash{$sedolelement}}) { print "$_\n"; } } #$NumTradingSedols = 1; } else { #print "this is j $j\n"; foreach $sedolelement (keys %Sellhash) { #print "the key is: $sedolelement te sedol is $sedol\n"; if ($sedolelement eq $sedol) { $condition = "TRUE"; print "the sedol is in the list so add the shares.\n"; $usekey = $sedolelement; $oldshares = $Sellhash{$sedolelement}[1]; } else { $condition = "FALSE"; $count++; } } if (($condition eq "FLASE") && ($count != 0)) { $Sellhash{"$sedol"} .= $shares; print "the new entry is $sedol $shares\n"; } else { $Sellhash{"$sedol"} = $Sellhash{"$sedol"} + $shares; $newtotal = $Sellhash{"$sedol"}; print "the new total shares for sedol: $sedol is $newtotal +\n"; } foreach $sedolelement (keys %Sellhash) { $total = $Sellhash{"$sedolelement"}; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Building a Hash of arrays from a hash of arrays based on a list?
by goldclaw (Scribe) on Jan 26, 2002 at 03:10 UTC | |
by evangraj (Initiate) on Jan 26, 2002 at 20:56 UTC | |
|
Re: Building a Hash of arrays from a hash of arrays based on a list?
by cfreak (Chaplain) on Jan 26, 2002 at 03:18 UTC |