Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Converting logs to CSV format (desperate help)

by diotalevi (Canon)
on Oct 16, 2002 at 06:49 UTC ( [id://205644]=note: print w/replies, xml ) Need Help??


in reply to Converting logs to CSV format (desperate 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;

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://205644]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-20 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found