Some thoughts
1. Implicit splitting on @_
$cols = split;
Provides a warning:
Use of implicit split to @_ is deprecated
If you have not already done so, you must add
use warnings; use strict;
to your script. (And heed these warnings.)
Consider changing $cols
to @cols
and instead using $#cols
in a for loop. For instance.
@cols = split; for (my $col=0; $col <= $#cols; $col++)
2. Is chomp required?
From split()
to perlfunc
:
If PATTERN is also omitted, it splits into a space (after skipping any leading space).
This means that your newline must also be removed, as it is considered a space character.
Therefore, chomp()
not required.
3. The number of open files
I believe that perl open()
is pretty fast, so it might be worth caching your data like weismat for example. While you are doing this, you can share a single file descriptor for all files and only open them when printing the cache. For instance:.
for ($i = 0; $i <= $#column; $i++) { open OUT, ">> column$i.txt" or die $!; print OUT $column[$i]; }
ETA: @column
This column contains columns migrated from DATA. Instead of printing, use:
$column[$col] .= $cols[$col] . " ";