in reply to Re: Database question: pulling a particular field from a flat database
in thread Database question: pulling a particular field from a flat database
Of course the original author should switch to a data format which is self-documenting (for instance make the first line a header line that says what fields are in use). And when you do that, the use of a hash slice makes things very easy - just read the list of field names out of the header line!#! perl use strict; my $file = shift(@ARGV) || "foo.txt"; open(FH, $file) or die("Cannot read '$file': $!"); my @field_list = qw(put in reasonable names here for your data); while (<FH>) { chomp; my %row; @row{@field_list} = split /\|/, $_; my ($field_data, $comment) = split /;/, $row{data}; print "$field_data\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re (tilly) 2: Database question: pulling a particular field from a flat database
by foogod (Friar) on Sep 08, 2001 at 00:37 UTC |