Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: .csv file in to hash of hashes for a Berkley DB (for a hash newbie)

by Tux (Monsignor)
on Jun 12, 2013 at 10:05 UTC ( #1038422=note: print w/ replies, xml ) Need Help??


in reply to .csv file in to hash of hashes for a Berkley DB (for a hash newbie)

And reading the data can be so easy with Text::CSV_XS. In my perception even easier than with your snippet. Mind that you have two trailing columns that you do not use.

use Text::CSV_XS; my $stbdetails = "stbdetails.csv"; open my $fh, "<", $stbdetails or die "$stbdetails: $!"; my $csv = Text::CSV_XS->new ({ binary => 1, auto_diag => 1 }); $csv->bind_columns (\my ( $location, $date_active, $manufacturer, $hwver, $seria +l, $cardno, $currentsw, $os_ver, $epg_ver, $boxty +pe, $designation, $boxip, $boxmac, $codedate, $_flag, $_date, )); my %hash; while ($csv->getline ($cfh)) { $hash{$location} = { "Date Active" => $date_active, "Manufacturer" => $manufacturer, "HW Version" => $hwver, "Serial" => $serial, "Card No" => $cardno, "Current Software" => $currentsw, "OS Version" => $os_ver, "EPG Version" => $epg_ver, "Box Type" => $boxtype, "Designation" => $designation, "IP Address" => $boxip, "MAC Address" => $boxmac, "Code Date" => $codedate, }; }

Enjoy, Have FUN! H.Merijn


Comment on Re: .csv file in to hash of hashes for a Berkley DB (for a hash newbie)
Download Code
Replies are listed 'Best First'.
Re^2: .csv file in to hash of hashes for a Berkley DB (for a hash newbie)
by Doozer (Beadle) on Jun 12, 2013 at 12:00 UTC
    I have ended up going with MLDBM.

    DBM::Deep was good but MLDBM did exactly what I wanted. I only needed to read this .csv file into a database once. Now using MLDBM I can open the database and search for any field of any Set Top Box with ease.

    Thanks again for all the help on this.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1038422]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (6)
As of 2015-07-31 01:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (274 votes), past polls