I'm tidying up a script that splits a file into several other files.
The script is called like this:
splitter.pl < input.dat 3> out1.dat 4> out2.dat 5> out3.dat
Within the script, the lines output to different files depending on
a $type data field. The files are used like this:
my $fh = "FH$type";
open $fh, ">&=$streamnum{$type}" or die $!;
print $fh "some data from the input file";
Where %streamnum maps a $type to an output file descriptor.
This, of course, breaks under 'use strict' as print doesn't like to be
passed a variable for the filehandle (it treats it as a symbolic
reference).
Aha, I think. I'll replace the file stuff with one of the OO file
modules. so I've changed the code to:
my $fh = IO::File->new;
$fh->open(">&=$streamnum{$type}") or die $!;
$fh->print "some data from the input file";
But it seems that IO::File::open doesnt like the '&=FD' syntax as I get
an error saying:
Output C failed to open at ./split_web2.pl line 50, <> chunk 2
Whereas it worked find on the older, more clunky method.
I've also tried using the Filehandle module with the same (lack of)
results.
Any advice?
Dave...