in reply to Parse Pipe Delimited Text
I see three main problems that you need to solve here
firstly, you need to parse a pipe delimited file.
Ok, for this, you can use the CPAN module Text::CSV_XS
Why this, you ask ? isn't CSV for "comma separated variables?".. true enough, but inside this wonderful module, you can also specify the separator character, which in your case would be a pipe.
You could of course, also roll your own, with a simple call to the split function such as (this is very simplistic, probably too much so)
open(DATA,"myfile") or die "No, can't open the file"; while(<DATA>) { my @elements = split('\|',$_); # do something with the elements here }
Your second problem is to find out when a new file has arrived..
First, store the modified date of the file with a call to the Perl inbuilt function stat, or by using the File::Stat module.
Whenever your Perl script wakes up (cron job? or NT 'at' scheduler call)and decides to process the file, check the last modified date that you stored, with the one of the file. If they differ, ie: if the FTP folder file has a more recent date, that means you should parse the file again...
Well, the third problem, outputting to an HTML table, is sort of simple, I think.. for completeness sake, I'll put a small pseudo-code like segment here that describes how it would be done...please note: this is untested
open(INPUT,"myfile") or die "Can't open file"; print "<html><head><title>My page</title></head><body>"; print "<table>"; while(<INPUT>) { my @elements = split('\|',$_); print "<tr>"; foreach my $el(@elements) { print "<td>$el</td>"; } print "</tr>"; } print "</table></body></html>";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Parse Pipe Delimited Text
by MrNobo1024 (Hermit) on Apr 03, 2001 at 06:09 UTC |