The Code: use strict; use warnings; use Tie::Handle::CSV;
my $qbook = Tie::Handle::CSV->new('C:\Documents and Settings\Soham Das\Desktop\Quotes.csv',header=>1); my $tradebook = Tie::Handle::CSV->new('C:\Documents and Settings\Soham Das\Desktop\Transactions.csv',header=>1); my $dailytrade={}; my $portfolio={}; my $singletrade={}; while(my $mktdates =<$qbook>) { while(my $trades=<$tradebook>) { if($trades->{'Date'} eq $mktdates->{'Date'}) { $singletrade->{'Action'}=$trades->{'Action'}; $singletrade->{'Scrip'}= $trades->{'Scrip'}; $singletrade->{'Shares'}= $trades->{'Shares'}; $singletrade->{'Price'}=($trades->{'Price'})*1.00845; $dailytrade->{$singletrade->{'Scrip'}}= $singletrade; # print $dailytrade->{$singletrade->{'Scrip'}}->{'Price'},"\n"; } #Update the portfolio } } close $qbook ; close $tradebook; Soham P.S: apologies for the previous mail being a blank mail, it was a mistake ________________________________ From: Soham Das <soham...@yahoo.co.in> To: beginners@perl.org Sent: Fri, 9 October, 2009 11:02:51 AM Subject: Re: Building a record on the fly via hash of hashes The code: ________________________________ From: Jim Gibson <jimsgib...@gmail.com> To: beginners@perl.org Sent: Fri, 9 October, 2009 11:00:55 AM Subject: Re: Building a record on the fly via hash of hashes At 10:14 PM -0700 10/8/09, Soham Das wrote: > Hello All, I am doing some file reading operation, and parsing the data(its a > CSV file) with a hash reference and then intend to store it in a record. > something like: loop: until file ends; > $hashref->{'A'}=$filehandle->{'Action'}; $hashref->{'B'}= > $filehandle->{'Name'}; $hashref->{'C'}= $filehandle->{'System'}; > $hashref->{'D'}=($filehandle->{'Price'}); $recordref->{$hashref->{'B'}}= > $hashref; loop : ends You are better off including some actual Perl code, including some sample data. > Here Action, Name,System,price are the CSV headers. Now, when the first line > is read, the details are parsed and stored in the $recordref as a hash > reference. Now when the loop iterates, and goes to the second line. The first > line contents are lost. Because the hash reference now points to the newer > data. How do I overcome this? More importantly do we have a push equivalent > for hash of hashes? No. Unless each record has a unique key, you are better off using an array of hashes, rather than a hash of hashes. Of course, you could use the line number as a unique key, but an array would be more efficient. -- Jim Gibson j...@gibson.org -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ ________________________________ Now, send attachments up to 25MB with Yahoo! India Mail. Learn how. Send free SMS to your Friends on Mobile from your Yahoo! Messenger. Download Now! http://messenger.yahoo.com/download.php