in reply to Parsing a 3-Column Tab-Deliminated File
Or, to go overkill one more step :) wrap that in Class::DBI:use DBI; my $dbh = DBI->connect("DBI:CSV:f_dir=.;csv_sep_char=\t") or die "Cann +ot connect: " . $DBI::errstr; $dbh->{'csv_tables'}->{'employees'} = { file => 'employees.txt'}; # now you have your choice of DBI commands. This one gets a ref to a +Array of Hashrefs my $aref = $dbh->selectall_arrayref("select * from employees", {Slice= +>{}}, ); # AoH $dbh->disconnect();
package My::Employees; use base qw/Class::DBI/; __PACKAGE__->connection("DBI:CSV:f_dir=.;csv_sep_char=\t",); __PACKAGE__->db_Main->{'csv_tables'}->{'employees'} = { file => 'emplo +yees.txt'}; # i'm guessing a little here .. it's a lot easier if the + file doesn't have an extension __PACKAGE__->table('employees'); __PACKAGE__->columns(Primary => qw/NAME/ ); # is it unique?? __PACKAGE__->columns(All => qw/NAME EMAIL OFFICE/); package main; my @all = My::Employees->retrieve_all; my $first = $all[0]; warn $first->EMAIL;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Parsing a 3-Column Tab-Deliminated File
by Hue-Bond (Priest) on Oct 03, 2006 at 15:23 UTC | |
by jZed (Prior) on Oct 03, 2006 at 15:50 UTC |