Anonymous Monk,
May I suggest Data Munging with Perl as a good place to start. I would also highly recommend Mastering Regular Expressions. I am going to give your problem a stab just because I haven't ever done something like this before in Perl.

Beware untested code - dragons lie ahead!

#!/usr/bin/perl -w use strict; open (INPUT,"file") or die "Unable to open file : $!"; open (OUTPUT,">outfile") or die "Problem with outfile : $!"; select OUTPUT; $/ = ""; $\ = "\n"; my @data; my $foo; my $bar; while (<INPUT>) { my @lines = split /\n/; my $blah; while (my $line = shift @lines) { $line =~ s/^\s*//; last if ($line =~ /^Total/); next if (/^\s*$/); if ($line =~ /^([^:]*):(.*)$/) { $foo = $1; $bar = $2; next; } elsif ($line =~ /^(\d+)$/) { $blah = $1; next; } else { my @stuff = split /\s{2,}/ , $line; push @data , join ',' , ($bar, "\"$foo\"", $blah, "\"$stuf +f[0]\"", "\"$stuff[1]\"", $stuff[2]); } } } print foreach(@data);
Now as I said - I wrote that code just because I have never done this sort of thing before. That means I am not very experienced and there is most likely a better way.

Cheers - L~R


In reply to Re: pulling fields out of a ascii print file by Limbic~Region
in thread pulling fields out of a ascii print file 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.