sdyates has asked for the wisdom of the Perl Monks concerning the following question:
Here is a sample of the text I am trying to parse:
Well I want to read a text file wiht this information, then place each tab separated item into a separate part of the array so I can do some work, then dump it out with all the without any extra tabs. Right now I get the text I need, but with a bunch of extra tabs and other informatio I would rather not have.Berlinda Girl Newmarket Lord, army; shield 54 + Soccer Berlindis Girl Newmarket Lord, army; shield 32 + Football
Here is my code:
ProcessRedFile(); sub ProcessRedFile { open (READ, "dump.txt"); $Counter=(); open (OUT, ">/Users/simondyates/Desktop/OutFile.txt"); @File =<READ>; foreach $File(@File) { @Format = split(/ *\s\s */,$File); push (@Finish, @Format); } } $x=0; print OUT "\t"; $x=0; while ($x<200) { @Test = split(/\t/,$Finish[$x]); push (@Test2, @Test); $x++; } @Finish = @Test2; while ($x<200) { if ($f eq 1) { print OUT "$Finish[$x]\t"; } elsif ( $f eq 2) { print OUT "$Finish[$x]\t"; } elsif ( $f eq 4) { print OUT "$Finish[$x]\t"; } elsif ( $f eq 5) { print OUT "$Finish[$x]\t"; } elsif ( $f eq 8) { print OUT "\n"; $f=0; } $x=$x+1; $f++; } close READ; close OUT;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parsing simple text, made difficult
by liverpole (Monsignor) on May 27, 2007 at 15:04 UTC | |
|
Re: Parsing simple text, made difficult
by derby (Abbot) on May 27, 2007 at 14:54 UTC | |
|
Re: Parsing simple text, made difficult
by GrandFather (Saint) on May 27, 2007 at 20:54 UTC | |
|
Re: Parsing simple text, made difficult
by varian (Chaplain) on May 27, 2007 at 16:05 UTC |