Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Reading File and Seperating into columns

by Tux (Monsignor)
on Sep 25, 2013 at 18:12 UTC ( #1055720=note: print w/ replies, xml ) Need Help??


in reply to Reading File and Seperating into columns

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, ">", "$file.read" or die "Couldn't open $file.read +: $!"; 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


Comment on Re: Reading File and Seperating into columns
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2014-08-22 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (147 votes), past polls