I have a tab delimited file that is a DB export of an addressbook. I want to map the data from this file into a hash that has associative keys. I can read the data into an array with no problem, but is there an easy way to map this into the hash? Or is there a way to split things into the hash instead of an array? I believe going from the array to a hash isn't too difficult, but I need to get to an associative hash. Maybe array -> hash -> associative hash? Don't know, that's why I'm posting this!
/usr/bin/perl -w
use strict;
my $import_file = shift || 'addresses';
my @tmp;
my %import_data =(
'id' => '',
'username' => '',
'domain' => '',
'address' => '',
'firstname' => '',
'lastname' => '',
'nickname' => '',
'type' => '',
'street' => '',
'city' => '',
'state' => '',
'zip' => '',
'country' => '',
'company' => '',
'home_phone' => '',
'work_phone' => '',
'pager' => '',
'cellular' => '',
'fax' => '',
'other' => '',
'birth_month' => '',
'birth_day' => '',
'birth_year' => '',
'birthday' => 'undef',
'title' => '',
'status' => '',
'time_stamp' => '',
'middleinitial' => '',
'nameprefix' => 'undef',
'namesuffix' => 'undef',
'street2' => '',
'website' => '',
'notes' => '',
'department' => 'undef',
'assistant' => 'undef',
'dstreet' => '',
'dstreet2' => '',
'dcity' => '',
'dstate' => '',
'dzip' => '',
'dcountry' => '',
'dphone1' => 'undef',
'dphone2' => 'undef',
'daddress' => '',
'dspouse' => 'undef',
'danniversary_day' => '',
'danniversary_month' => '',
'dnotes' => 'undef',
'dwebsite' => '',
'daddress2' => '',
'danniversary_year' => '',
'category' => '',
'prime_phone' => '',
);
open(FILE, "< $import_file") or die "Cannot open $import_file ERR: $!\
+n";
while (<FILE>) {
@tmp = split /\t/;
#map @tmp to %import_data here
#then call a sub-routine to manipulate
}
close FILE;