Uncertain if this is as big as it gets or what, but I tried this:
          where %Myusgs  is keyed from $USGS_QD_ID
                   [0] points to Quad name
                   [1] points to element of array holding input data

                  %Myquad  is keyed from $QUAD_NAME
                   [0] points to USGS
                   [1] points to element of array holding input data
                
                  %MyState is keyed from each state field
                   [0] points to USGS
                   [1] holds array point separated by ; for all related data
by state
                  %MyData  is keyed on array index
                   holds input data
        By this, you have exact access via usgs and quad and for state you
have all the necessary data.  Probably not all thought out, but have run it
and it does have the data.

Wags ;)
============================================================

Script starts on next line
my %Myusgs  = ();
my %Myquad  = ();
my %MyState = ();
my @MyData  = ();
my $MyId = 0;

while( <DATA> ) {
        chomp;
                next if ( /^\s*$/ );
                next if ( /^#/ );
        ( $FILE_NAME, $USGS_QD_ID, $QUAD_NAME, $ST_NAME1, $ST_NAME2,
          $ST_NAME3, $ST_NAME4, $DATE_REV, $DATE_PUB ) = split( /\t/ );
                $Myusgs{$USGS_QD_ID}[0] = $QUAD_NAME;
                $Myquad{$QUAD_NAME}[0]  = $USGS_QD_ID;
                $Myusgs{$USGS_QD_ID}[1] = $MyId;
                $Myquad{$QUAD_NAME}[1]  = $MyId;
                $MyData[$MyId] = $_;
                
                if ( $ST_NAME1 gt '') {
                        if ( ! defined $MyState{$ST_NAME1}[0] ) {
                           $MyState{$ST_NAME1}[0] = '';
                           $MyState{$ST_NAME1}[1] = '';
                         } 
                        $MyState{$ST_NAME1}[0] .= $USGS_QD_ID . ';';
                        $MyState{$ST_NAME1}[1] .= $MyId . ';';
                 }              
                 
                if ( $ST_NAME2 gt '') {
                        if ( ! defined $MyState{$ST_NAME2}[0] ) {
                           $MyState{$ST_NAME2}[0] = '';
                           $MyState{$ST_NAME2}[1] = '';
                         } 
                        $MyState{$ST_NAME2}[0] .= $USGS_QD_ID . ';';
                        $MyState{$ST_NAME2}[1] .= $MyId . ';';
                 }
                if ( $ST_NAME3 gt '') {
                        if ( ! defined $MyState{$ST_NAME3}[0] ) {
                           $MyState{$ST_NAME3}[0] = '';
                           $MyState{$ST_NAME3}[1] = '';
                         } 
                        $MyState{$ST_NAME3}[0] .= $USGS_QD_ID . ';';
                        $MyState{$ST_NAME3}[1] .= $MyId . ';';
                 }
                if ( $ST_NAME4 gt '') {
                        if ( ! defined $MyState{$ST_NAME4}[0] ) {
                           $MyState{$ST_NAME4}[0] = '';
                           $MyState{$ST_NAME4}[1] = '';
                         } 
                        $MyState{$ST_NAME4}[0] .= $USGS_QD_ID . ';';
                        $MyState{$ST_NAME4}[1] .= $MyId . ';';
                 }
                $MyId++;
=head1        
                $landhashes[$cnt++] = { file_name  => $FILE_NAME, 
                                                                usgs_qd_id
=> $USGS_QD_ID, 
                                                                quad_name
=> $QUAD_NAME, 
                                                                st_name1
=> $ST_NAME1, 
                                                                st_name2
=> $ST_NAME2, 
                                                                st_name3
=> $ST_NAME3, 
                                                                st_name4
=> $ST_NAME4, 
                                                                date_rev
=> $DATE_REV, 
                                                                date_pub
=> $DATE_PUB
                                                       };
=cut
}
# close( INPUT );

#print Dumper( \@landhashes );

print Dumper( \%Myusgs );
chomp(my $MyInput = <STDIN>);
print Dumper( \%Myquad );
chomp($MyInput = <STDIN>);
print Dumper( \%MyState );
chomp($MyInput = <STDIN>);
^----------------------- Script ends here

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, June 05, 2002 11:48
To: [EMAIL PROTECTED]
Subject: parse file into hash



Hello,
    I am new with perl and was hoping to get some direction.

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?


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

Reply via email to