Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Fix this to taste - it's my best guess at what you need. It reads one header per file and then multiple records per file.

use strict; use warnings; use constant HEADER => q[ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1 +"> <style type="text/css"> <!-- body { font-family: verdana; font-size: 7px; } tbody { font-family: verdana; font-size: 9px; } --> </style> </head> <body> <TABLE width=955 cellPadding=1 cellSpacing=0> <TBODY> <TR vAlign=top> <TD width="59" height=16> <P class=Table>File Name, &nbsp;&nbsp; +&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P></TD> <TD width="68" height=16> <P class=Table>Author,&nbsp;&nbsp;&nbs +p;&nbsp;&nbsp; </P></TD> <TD width="144" height=16> <P class=Table>Date (MM/DD/Year),&nbs +p;&nbsp;&nbsp; </P></TD> <TD width="96" height=16> <P class=Table>TIME (H:M:S),&nbsp;&nbs +p;&nbsp;&nbsp;&nbsp;&nbsp; </P></TD> <TD width="114" height=16> <P class=Table>Version No.,&nbsp;&nbs +p;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </P></TD> <TD width="59" height=16> <P class=Table>Number,</P></TD> <TD width="97" height=16> <P class=Table>Feature Name,</P></TD> <TD width="125" height=16> <P class=Table>Paragraph Number,</P>< +/TD> <TD width="173" height=16> <P class=Table>Requirement Number</P> +</TD> </TR> ]; use constant FOOTER => q[ </TBODY> </TABLE> </body> </html>]; sub fixupRecord { my $record = shift; for (qw(FileName Author Date Time Version Number FeatureName ParagraphNumber RequirementNumber)) { $record->{$_} = '&npsp;' unless defined $record->{$_} } } sub formatRecord { my $record = shift; fixupRecord( $record ); qq[ <TR vAlign=top> <TD width="59" height=16> <P class=Table>@{[$record->{FileName}] +}</P></TD> <TD width="68" height=16> <P class=Table>@{[$record->{Author}]}, +</P></TD> <TD width="144" height=16> <P class=Table style="MARGIN-TOP: 0px +; MARGIN-BOTTOM: 0px">@{[$record->{Date}]}</P></TD> <TD width="96" height=16> <P class=Table style="MARGIN-TOP: 0px; + MARGIN-BOTTOM: 0px">@{[$record->{Time}]}</P></TD> <TD width="114" height=16> <P class=Table style="MARGIN-TOP: 0px +; MARGIN-BOTTOM: 0px">@{[$record->{Version}]},</P></TD> <TD width="59" height=16> <P class=Table style="MARGIN-TOP: 0px; + MARGIN-BOTTOM: 0px">@{[$record->{Number}]},</P></TD> <TD width="97" height=16> <P class=Table style="MARGIN-TOP: 0px; + MARGIN-BOTTOM: 0px">@{[$record->{FeatureName}]}</P></TD> <TD width="125" height=16> <P class=Table style="MARGIN-TOP: 0px +; MARGIN-BOTTOM: 0px">@{[$record->{ParagraphNumber}]},</P></TD> <TD width="173" height=16> <P class=Table style="MARGIN-TOP: 0px +; MARGIN-BOTTOM: 0px">@{[$record->{RequirementNumber}]}</P></TD> </TR> ]; } print HEADER; for my $filename (@ARGV) { my $file = do { local (@ARGV, $/) = $filename; <> }; my %record; for ([ Author => qr/^Author\s+:\s+(.+)/m ], [ Number => qr/^Number\s+:\s+(.+)/m ], [ Version => qr/^Version Number\s+:\s+(.+)/m ], [ FeatureName => qr/^Feature\s+:\s(.+)/m ], [ FileName => qr/^File Name\s+:\s(.+)/m ], [ Date => qr/^Modification Date\s+:\s(.+)/m ]) { @record{$_->[0]} = $file =~ $_->[1]; $record{$_->[0]} =~ s/^\s+//; $record{$_->[0]} =~ s/\s+$//; } $file =~ s/^.+?Paragraph Number\s+Requirement Number\s+Last Modifi +ed\n//s; for (split /\n/, $file) { my %instance = %record; @instance{qw(ParagraphNumber RequirementNumber)} = split; print formatRecord( \%instance ); } } print FOOTER;
__SIG__ printf "You are here %08x\n", unpack "L!", unpack "P4", pack "L!", B::svref_2object(sub{})->OUTSIDE;

In reply to Re: Converting logs to CSV format (desperate help) by diotalevi
in thread Converting logs to CSV format (desperate help) by pelp

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-03-28 13:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found