----- Original Message ----
From: Manoj <[EMAIL PROTECTED]>
To: beginners@perl.org
Sent: Friday, March 14, 2008 12:09:42 AM
Subject: Hash & CSV

Hello list,

 

Have a CSV file with the first column as unique which I am taking as hash
key and rest of the line as hash value. I am opening the file and putting to
hash after reading each line. There are two questions from me. 

 

1)       How to find the performance and time taken by Perl script?

2)       Is there any optimal method for reading a CSV file and put to hash
table.

 

Note: This is only a part of script doing and I am supposed to do this with
out using any default modules.
Thanks
Manoj
------------------------------------------------------------------------
Hi Manoj


1)        How to find the performance and time taken by Perl script?

For benchmarking the perl scripts you can use the Benchmark module.

http://search.cpan.org/~rgarcia/perl-5.10.0/lib/Benchmark.pm

2)       Is there any optimal method for reading a CSV file and put to hash 
table.

May have better approaches however this read CSV into Hash

use Data::Dumper;
open(INFILE, "<", "sample.csv") or die $!;
my %hsh;
%hsh = ( %hsh, (split(/,/, $_))[1,2] ) while ( <INFILE> );
print Dumper \%hsh;

Hope this helps,

Thanks,
Prabu







      
____________________________________________________________________________________
Be a better friend, newshound, and 
know-it-all with Yahoo! Mobile.  Try it now.  
http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ 

Reply via email to