On Wed, Jun 05, 2002 at 02:47:55PM -0400, Alaric Joseph Hammell wrote:
> I am attempting to parse a the attached .txt file.
> 
> i need to be able to access the information by unique keys, QUAD_NAME and
> USGS_QD_ID. Also, I want to be able to do a somewhat less exact access byt
> ST_NAME.
> 
> I was thinking that I would use a hash of arrays.  any suggestions on
> parsing the file?

My immediate thought would be to use DBI and DBD::CSV, found on CPAN.  For
example, this would list all records where the ST_NAME1 field is
'Washington':

    use DBI;
    use strict;


    my $dbh = DBI->connect(
        "dbi:CSV:f_dir=.;csv_eol=\012;csv_sep_char=\t",
        undef, undef, { RaiseError => 1 }
    );

    my $sth = $dbh->prepare("SELECT * FROM landuse WHERE ST_NAME1 = 'Washington'");
    $sth->execute;

    while (defined(my $row = $sth->fetchrow_hashref)) {
        print "--\n", (map { "$_: $$row{$_}\n" } keys(%$row)), "--\n";
    }
 
    $sth->finish;
    $dbh->disconnect;


The subset of SQL supported is still fairly rich, allowing you to search on
any criteria you wish.  See perldoc DBD::CSV for further information.


Michael
--
Administrator                      www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to