tao wang wrote:
thanks.  I need parse a text file, which is like a
text database file, but not very structured. many
thanks.

In that case you will need to decide what the "structure" is, and what you can guarantee. A normal text database is going to be parsed in the following general manner:

open the file, step through the delimited portions of the file, in many cases line by line with a while loop, until some condition is met, in many cases EOF, possibly split on some character(s) within each delimited portion, and store those to some data structure that can then be manipulated or fire off events that handle things such as a start of a new element, the body of an element, the end of an element, etc.

perldoc -f open
perldoc perlopentut
perldoc -f split
perldoc -f close

For instance a comma delimited file could be handled like so (though some would prefer DBD::CSV)...

my $file = '/path/to/file.csv';

my $INPUTFILE;
open($INPUTFILE,"$file") or die "Can't open input file for reading: $!";

while (my $line = <$INPUTFILE>) {
my @values = split(/,/,$line);

my $count = 0;
foreach my $val (@values) {
print "Element $count: $val\n";
$count++;
}
}

close($INPUTFILE);

--untested--

http://danconia.org


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

Reply via email to