A file handle is an abstract indicator for accessing a file. It is retrieved after successfully opening the file using the file name. Afterwards the file handle is used instead of the file name for all file operations.
Questions tagged [filehandle]
407 questions
4
votes
1 answer
Perl Cannot Binmode STDOUT After Untie Filehandle
I need to disable progressive buffering of an HTTP response.
I've got this working in Perl using a file handle class:
$|=1;
$TIE = tie(*STDOUT,__PACKAGE__);
Print statements are stored in an array and are retrieved via the following:
$buffer = tied…

xpsd300
- 175
- 2
- 11
4
votes
1 answer
Why I am getting "print() on closed filehandle with bad file descriptor" in my Perl script?
I have a TCP server in Perl (revision 5.0 version 8 subversion 0) which use this subroutine to log in a file.
sub logger {
return if ($LOGFILE eq "") ;
my ($idt, $str) = @_ ;
unless( defined($str) ) {
$str = $idt ;
$idt = '' ;
}
my…

user1334149
- 161
- 1
- 7
3
votes
3 answers
Usage of defined with Filehandle and while Loop
While reading a book on advanced Perl programming(1), I came across
this code:
while (defined($s = <>)) {
...
Is there any special reason for using defined here? The documentation for
perlop says:
In these loop constructs, the assigned…

sidyll
- 57,726
- 14
- 108
- 151
3
votes
1 answer
Any way to work around the fact that __DATA__ is not a filehandle, even though it's referred that way in all the documentation
All the documentation I've been reading about __DATA__ says stuff like, "the special filehandle" but it's not a filehandle is it?
https://perldoc.perl.org/perldata#Special-Literals
The DATA file handle by default has whatever PerlIO layers were in…

Walt Howard
- 7,676
- 1
- 16
- 11
3
votes
4 answers
Writing to a file in perl
I want to write the key and value pair that i have populated in the hash.I am using
open(OUTFILE,">>output_file.txt");
{
foreach my $name(keys %HoH) {
my $values = $HoH{$name};
print "$name: $values\n";
}
}
close(OUTFILE);…

kunal
- 107
- 2
- 2
- 6
3
votes
3 answers
How can I redirect the output from one filehandle into another?
I want to set up a pipeline of processes from within Perl (running on Linux), consisting of two parts run at separate times.
Eg:
Start the consumer process:
open( OUT, "| tar xvf - " ) || die "Failed: tar: $!";
then much later start the producer…

Martin
- 9,674
- 5
- 36
- 36
3
votes
1 answer
How to detect a "file handle leak" in NodeJS?
I have just lost several days with the following situation:
I'm running a NodeJS console application, mostly from VS Code. The app scrapes various data and files from the web. Naturally, it deals with a high number of HTTP requests and disk reads…

Jonas Sourlier
- 13,684
- 16
- 77
- 148
3
votes
1 answer
Reading from a filehandle reference in a subroutune
I'd like to pass a reference to a file handle to a subroutine, such that code in the sub can read from the file and the position in the file handle changes in the calling environment, rather like using a pointer in C.
This kind of thing:
open my…

phlatphish
- 95
- 5
3
votes
1 answer
print() on a closed filehandle OUT at
I am very new to Perl (just seen one Youtube video on it). I want to make a script that takes will take two .csv files and append them together and make a new .csv file. I don't want the two .csv files that are being appended to be altered. I also…

tarkan
- 69
- 1
- 8
3
votes
7 answers
Explicitly close file handles or let the OS close them in Unix C programming?
In Unix C programming, is it considered good practice to explicitly close file handles before the process exits, or is it instead good practice to let the OS close the file handles and thus avoid unnecessary code?
Which of the two would generally be…

Erik Öjebo
- 10,821
- 4
- 54
- 75
3
votes
3 answers
Perl: creating zombies through open() without close()
Here is the problem:
I've a daemon which get requests from a client, executes a function (from some module) due to the request and returns an answer to the client.
After the fork() I close STDIN,STDOUT and STDERR.
One function is to check dmesg.…

olo
- 33
- 2
3
votes
2 answers
How to PREPEND text to a file in Swift or Objective C?
Please note that I'm not asking how to append texts at the end of the file. I'm asking how to prepend texts to the beginning of file.
let handle = try FileHandle(forWritingTo: someFile)
//handle.seekToEndOfFile() // This is for…

7ball
- 2,183
- 4
- 26
- 61
3
votes
1 answer
Perl DATA filehandle is empty when read
I have a Perl module with a template (for processing by the Template module) stored between the __DATA__ and __END__ keywords at the end of the file. When attempting to generate a file using the template, the resulting file comes out empty with no…

Rob Streeting
- 1,675
- 3
- 16
- 27
3
votes
2 answers
Changing the value of stdout in a C++ program
I have a Windows C++ program that is doing something like:
FILE* pf = ...;
*stdout = *pf; // stdout is defined in stdio.h
I'm looking for an explanation about what happens when you change the value of the stdout file handle. Is this just a…

criddell
- 14,289
- 9
- 41
- 45
3
votes
7 answers
Appending to a global file handle, is it bad?
Lets say there are multiple functions throughout my program that need to append data to a certain file. I open the file at the beginning of the program with a global file handle so I can append to it wherever I need to. (Note that I know I could…

user318747
- 1,418
- 2
- 16
- 29