in reply to Multiple simultaneous filehandles
my $fh = "OUTPUT" . $i;
Don't do that. Since version 5.6, Perl allows you to conveniently put filhandles in lexically scoped variables. In your case you're indexing by a number, so an array of handles is probably the best choice.
# before the if ($. == 1) my @fhs; ... # open one open $fhs[$i], ">", $filename or die "Cannot open the output file: $!" +; ... # use it print {$fhs[$i]} "$line[0]\t$line[$i]\n";
Note it's important to control the scope of @fhs, so it's visible to your code that uses it. When it goes out of scope, the files are closed.
Update: fixed syntax error, thanks eyespoplikeamosquito++!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Multiple simultaneous filehandles
by eyepopslikeamosquito (Archbishop) on Oct 24, 2006 at 06:42 UTC |