in reply to Re: Parsing a date from comma-delimited file
in thread Parsing a date from comma-delimited file
i think qq is correct here when he says you should try using a CSV module from CPAN.DBD::CSV or DBD::AnyData. With it you could just use a select style query on the file from STDIN. like so ...
with the test.csv being (example)use DBD::CSV; my $input = "test.csv"; my $dbh = DBI->connect(qq{DBI:CSV:}); $dbh->{'csv_tables'}->{'info'} = { 'file' => "$input", 'eol' => "\n", 'col_names' => ["ID", "date"]}; my $sth = $dbh->prepare("SELECT * FROM info WHERE date=?"); print "Enter a date to seach for MM/DD/YYYY: "; my $date = <STDIN>; chomp($date); $sth->execute($date); my @array; while(@array = $sth->fetchrow_array){ print "$array[0], $array[1]\n"; }
1,02/03/2004 2,09/04/1976 3,01/13/1998 4,02/04/2006 5,02/07/2004 6,02/03/2004which should give you want you want
localhost% ./csv Enter a date to seach for MM/DD/YYYY: 02/03/2004 1, 02/03/2004 6, 02/03/2004
|
|---|