Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Re: Parsing Text from a File to HTML Table

by kcott (Chancellor)
on Oct 28, 2013 at 02:56 UTC ( #1059940=note: print w/replies, xml ) Need Help??

in reply to Parsing Text from a File to HTML Table

G'day anupchandu,

If the status and dates contain no spaces, a quick and dirty fix might be:

my $status = shift @cells; my $end = pop @cells; my $start = pop @cells; print "<td>$_</td>" for ($status, join(' ', @cells), $start, $end);

A more robust solution would be to work on the basis that the formats of the status and dates are known: if you match them, whatever is left in the middle is the company name. Here's an example:

# Do this once: my $status_re = qr{\w+}; my $date_re = qr{\d{2}-\w{3}-\d{4}}; my $log_re = qr{^($status_re)\s+(.*?)\s+($date_re)\s+($date_re)\R$}; ... # Do this in the while loop print "<td>$_</td>" for $line =~ $log_re;

As you can see from earlier responses, our ability to provide you with a definitive answer is hampered by the lack of information in your original post. A better question gets better answers: read the guidelines in "How do I post a question effectively?" to see how you could have improved on this.

-- Ken

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1059940]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-06-24 00:20 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (126 votes). Check out past polls.