Alaric Joseph Hammell wrote at Wed, 05 Jun 2002 20:47:55 +0200:
> 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?
> ...
> FILE_NAME USGS_QD_ID QUAD_NAME ST_NAME1 ST_NAME2
>ST_NAME3 ST_NAME4 DATE_REV DATE_PUB
> LKE49094 49094-A1 KENORA Minnesota
> 67 68
> LCA48124 48124-A1 CAPE FLATTERY Washington
> 68 68
> LVI48122 48122-A1 VICTORIA Washington
> 74 76
> LCO48120 48120-A1 CONCRETE Washington
> 62 62
I agree to Michael that using an existing module is the best way.
In this case, it's quite O.K. to write it directly
(because the sql-statement hides a little bit, too).
use enum qw( FILE_NAME USGS_QD_ID QUAD_NAME ST_NAME1 ST_NAME2 ST_NAME3 ST_NAME4
DATE_REV DATE_PUB );
open FILE, "<dat.txt" or die "Can't open ... $!";
while (<FILE>) {
chomp;
my @fields = split /\s+/, $_;
# now you can acess like:
print $fields[FILE_NAME];
# or
print @fields[ST_NAME1, ST_NAME2];
}
close FILE;
Best Wishes,
Janek
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]