The ">" should not be part of the filename; since you are using the three-argument version of
open (good for you), the
> is already specified in the open command, and doesn't need to be in the filename as well. Change
$sectorOutputFiles[$sector]='>'.$path.$filenamefirstpart.$sector.".txt"; to
$sectorOutputFiles[$sector]=$path.$filenamefirstpart.$sector.".txt";, and it will work. (At least, it did for me when I declared
my $filenamefirstpart = ''; and fixed the filename.)
Working SSCCE:
use strict;
use warnings;
my ($sector,$path);
my @sectorOutputFiles;
my @fh;
$path="blah";
my $filenamefirstpart='';
for($sector=0;$sector<12;$sector++){
$sectorOutputFiles[$sector]=$path.$filenamefirstpart.$sector.".txt
+";
print STDERR $sectorOutputFiles[$sector], "\n";
open($fh[$sector],'>',$sectorOutputFiles[$sector])
or die "Can't open sector filehandler for writing: $!\n";
}