http://www.perlmonks.org?node_id=1055720


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