# Use strict and warnings -- ALWAYS! use strict; use warnings; # Declare things that might change at the top of the program my $input = "dump.txt"; my $output = "/Users/simondyates/Desktop/OutFile.txt"; # Open the output OUTSIDE of the subroutine my @Finish = ProcessRedFile(); # Check the return value to see if the file was open (OUT, ">", $output) or die "Can't write '$output' ($!)\n"; print OUT "\t"; my @Test2 = ( ); my $x; for ($x = 0; $x < @Finish; $x++) { my @Test = split(/\t/, $Finish[$x]); push @Test2, @Test; } @Finish = @Test2; my $f = 0; while ($x < 200) { # Consolidate -- all branches for $f in {1, 2, 4, 5} did the same thing! if ($f == 1 or $f == 2 or $f == 4 or $f == 5) { print OUT "$Finish[$x]\t"; } elsif ($f == 8) { print OUT "\n"; $f=0; } $x = $x + 1; $f++; } close OUT; # # Consider choosing a better subroutine name -- I have no # idea what a "Red File" is ... ?? # sub ProcessRedFile { open (READ, $input) or die "Can't read '$input' ($!)\n"; my @File = ; my @lines = ( ); foreach my $File (@File) { # This regex doesn't make much sense -- you're trying # to split on 2 whitespace character with optional leading # or trailing spaces?? Why not just split(/\s\s+/, $file)?? my @Format = split(/ *\s\s */, $File); push @lines, @Format; } close READ; return @lines; }