Posted by Frank Hale on 1999-03-18
Is there a way to read a file into a hash which the fields extend over
multiple lines?
I can do it but I have to strip off newline characters and this f's up
the formatting of the data.
Here is the code I have so far but it will only read fields if they
don't have newline characters in them. In other words it will mess up as
soon as it hits a newline character messing the data up in each field.
#!/usr/bin/perl
@fieldList = qw(Index Message);
open(FILE, "<forum_messages.dat");
foreach $line (<FILE>) {
@data{@fieldList} = split(/##/, $line, scalar @fieldList);
foreach (@fieldList) {
printf("%10.10s = %s", $_, $data{$_});
}
}
close(FILE);
--
From: Frank Hale
Email: frankhale@xxxxxxxx.xxx.xxx
ICQ: 7205161
Website: http://www.franksstuff.com
Previous post | Next post | Timeline | Home