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>";

HTH
Update: Fixed the code segments.. ack, can't believe I didn't put that in :(.. much respect to MrNobo1024
Update 2: Changed the name of the file handle from the reserved DATA to INPUT. DATA still works, but its not very good practice, as pointed out by others.

In reply to Re: Parse Pipe Delimited Text by tinman
in thread Parse Pipe Delimited Text by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.