in reply to Converting fixed record length files to pipe delimited

Yikes! That code didn't get wrapped for some reason, and it's throwing the navigation table way off kilter. Anyway.

The code you posted is really Perl 4 style, with a whole whack of arrays instead of the Perl 5 style Array of Arrays (or AoA as you will hear more often). AoA is a much easier way to implement what you have done. Easier is better, no?

I would define your input file format, first, in a structure, and then write a loop to use this information to re-parse the file. Consider making an array that has only the start positions of each of the fields:
# Define the format of the file my (@file_format) = ( 0, 3, 53, 60, 67, 74, # etc. 241+169, # Last position, presumably );
Now the length of each field $n, for substr() purposes, at least, is simply $file_format[$n+1] - $file_format[$n]. Note that the last entry in the table shouldn't be used, that is, $n should only go as high as $#file_format-1.

Now you can put each line into an array as you read it in, and then write it to a file straight away. Just open both files at the same time using two different filehandles, such as IN_FILE and OUT_FILE. You are putting your data into temporary arrays, but since the data is only used exactly once.
my (@field_data); for (my $i = 0; $i < $#file_format; $i++) { $field_data[$i] = substr($_, $file_format[$i], $file_format[$i+1]- $file_format[$i]); # Clean up as required, by trimming $field_data[$i] =~ s/\s+$//; } print OUT_FILE join('|', @field_data);
If you want, you can use unpack instead, but apart from stylistic differences, there is no real point unless you need maximum speed (i.e for 5 million line files, or what have you).