Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Using Text::CSV_XS or its slower Text::CSV, that would look like

#!/usr/bin/perl use 5.14.2; use warnings; use Text::CSV_XS; #Read between lines 40 - 112 from *.in, cut the lines up using pipe de +limitation. for my $file (glob "*.in") { open my $read, "<", $file or die "Couldn't open $file: $!" +; open my $write, ">", "$" or die "Couldn't open $ +: $!"; my $csv_in = Text::CSV_XS->new ({ binary => 1, sep_char => "|", +auto_diag => 1 }); my $csv_out = Text::CSV_XS->new ({ binary => 1, sep_char => "\t", +eol => "\n", auto_diag => 1 }); $csv_out->print ($write, [ qw( Record Code Date Calculated_Percent +age Vehicle_PRN Vehicle_Registration Insurer_Rating_Number Insurer_Ra +ting_Text )]); my $print = 0; while (my $row = $csv_in->getline ($read) { $row->[0] =~ m/^99HEADER/ and $print = 1; $print and $csv_out->print ($write, $row); $row->[0] =~ m/^99TERMIN/ and $print = 0; } close $_ for $read, $write; }

Enjoy, Have FUN! H.Merijn
\n, eol =\t

In reply to Re: Reading File and Seperating into columns by Tux
in thread Reading File and Seperating into columns by Jalcock501

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chilling in the Monastery: (5)
    As of 2018-03-20 06:47 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (248 votes). Check out past polls.