First and foremost, you'll probably make your life easier in the long run if you open your code with use strict;use warnings - it'll catch a host of accidental mistakes. If you are working with tab-delimited fields, it's probably easier to use an existing parser like Text::CSV than rolling your own. Since the end-of-record markers are much rarer than tabs and new lines, you could catch that up front. And if you are concerned with formatting, it's probably easier to use sprintf to get things looking nice. Here's some basic code that (mostly) replicates what you've done, to help you with the CSV prototype:

#!/usr/bin/perl use strict; use warnings; use Text::CSV; my $file = "fielded.txt"; my $csv = Text::CSV->new({sep_char => "\t"}); # create a new objec +t open my $fh, "<", $file or die "Unable to open $file: $!"; while (my $data_ref = $csv->getline($fh)) { my @data = @{$data_ref}; if ($data[0] eq "'EOU'.") { # End of record code } elsif ($data[2] eq "u") { print "\n$data[3]" } elsif ($data[2] eq "p") { print "$data[3]\n" } else { #die "Unexpected line format encountered, $file, @data"; } } close $fh;

Update: I should point out you've made great strides since block extraction - congratulations.


In reply to Re: tab delimited extraction, formatting the output by kennethk
in thread tab delimited extraction, formatting the output by zzgulu

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.