in reply to Handling multiple output files simultaneously using arrays of filehandles and filenames

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"; }
  • Comment on Re: Handling multiple output files simultaneously using arrays of filehandles and filenames
  • Select or Download Code

Replies are listed 'Best First'.
Re^2: Handling multiple output files simultaneously using arrays of filehandles and filenames
by Cosmic37 (Acolyte) on Jan 21, 2021 at 15:19 UTC
    Thank you for that great advice. That was a dunderhead mistake and has indeed arisen out of changing version of open arguments.