Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Handling multiple output files simultaneously using arrays of filehandles and filenames

by pryrt (Abbot)
on Jan 21, 2021 at 16:35 UTC ( [id://11127211]=note: print w/replies, xml ) Need Help??


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 20:19 UTC
    Thank you for that great advice. That was a dunderhead mistake and has indeed arisen out of changing version of open arguments.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127211]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (7)
As of 2024-04-18 17:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found