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
6
votes
3 answers
Multiple filehandles opening the same file - is it a good practice?
I have grades.tsv file with three columns that show students' names, subjects and grades:
Liam Mathematics 5
Liam History 6
Liam Geography 8
Liam English 8
Aria Mathematics 8
Aria History 7
Aria Geography 6
Isabella …

zubenel
- 300
- 4
- 10
6
votes
1 answer
How to open a file handle on a string in Perl 6?
In Perl 5, I can open a filehandle on string like this:
open my $kfh, "<", \$message->payload;
I have a scenario that uses string as a filehandle and passes it to the open method:
my $fh = new IO::Zlib;
open my $kfh, "<",…

chenyf
- 5,048
- 1
- 12
- 35
6
votes
1 answer
Connection pool and File handles
We use Retrofit/OkHttp3 for all network traffic from our Android application. So far everything seems to run quite smoothly.
However, we have now occasionally had our app/process run out of file handles.
Android allows for a max of 1024 file…

fgysin
- 11,329
- 13
- 61
- 94
6
votes
3 answers
How to write 1 byte to a binary file?
I'm trying to write just one byte to a file in Python.
i = 10
fh.write( six.int2byte(i) )
Will output '0x00 0x0a'
fh.write( struct.pack('i', i) )
Will output '0x00 0x0a 0x00 0x00'
I want to write a single byte with the value 10 to the file.

reza
- 1,329
- 2
- 22
- 37
6
votes
2 answers
Filehandle for Output from System Command in Perl
Is there a filehandle/handle for the output of a system command I execute in Perl?

syker
- 10,912
- 16
- 56
- 68
6
votes
1 answer
Perl: Pass open file handle to a program reading STDIN
I read a few lines from STDIN. How can I pass the remaining of STDIN to a command that reads from standard input (e.g. md5sum or wc)?
I could do a:
read_a_few_lines_from_diamond_operator();
open (C, "|cmd");
while(<>) { print C }
close…

Ole Tange
- 31,768
- 5
- 86
- 104
6
votes
2 answers
How do I find if it is the last line while reading a file from within a loop in perl
I am working on a log parsing script using Perl. I am reading the log file as follows:
open(LOGFILE, "$logFile") || die "Error opening log file $logFile\n";
while()
{
#Processing statements goes here.
}
Now…

Viky
- 405
- 1
- 5
- 13
6
votes
5 answers
Regex: How to remove extra spaces between strings in Perl
I am working on a program that take user input for two file names. Unfortunately, the program can easily break if the user does not follow the specified format of the input. I want to write code that improves its resiliency against these types of…

cooldood3490
- 2,418
- 7
- 51
- 66
5
votes
3 answers
Can I find a filename from a filehandle in Tcl?
Similar to Can I find a filename from a filehandle in Perl? but in Tcl.
I plan to cache filename-filehandle associations anyway, so I'm asking purely out of curiosity--particularly of the "operating system wizardry" mentioned in the link. Is it…

Andrew Cheong
- 29,362
- 15
- 90
- 145
5
votes
5 answers
How to find open global filehandles in a perl program
I just tracked down a problem where I had to close all open filehandles for my Apache cgi script to continue. I traced the problem to Parse::RecDescent.
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/say/;
$|++;
print "Content-Type:…

CoffeeMonster
- 2,160
- 4
- 20
- 34
5
votes
2 answers
How to open Perl file handle to write data via sudo (or as another user)
I'd like to write data to a file, but the file handle should be opened with access permissions for a specific user.
Thus, the following statement:
open (FH, "> $filename") or die "$@\n";
would allow writing to a file as that particular user.
Is…

Alex Reynolds
- 95,983
- 54
- 240
- 345
5
votes
3 answers
What type is STDOUT, and how do I optionally write to it?
Does STDOUT have a "type"?
printf STDERR ("STDOUT = %s\n", STDOUT);
printf STDERR ("\*STDOUT = %s\n", *STDOUT);
printf STDERR ("\\\*STDOUT = %s\n", \*STDOUT);
Produces:
STDOUT = STDOUT
*STDOUT = *main::STDOUT
\*STDOUT = GLOB(0x600078848)
I…

Erik Bennett
- 1,049
- 6
- 15
5
votes
1 answer
How to make sure a file handle has been closed before next operation?
This is the code I have so far, I wonder if it's correct?
$handle = fopen($file, 'w') or die("can't open file");
$closed = fclose($handle);
while($closed){
DOAWESOMETHINGS(); // btw I only want to have this run once for each handle
$closed =…

Mohammad
- 7,344
- 15
- 48
- 76
5
votes
2 answers
Using __DATA__ in a program
It is used on Stack Overflow all the time but I really don't understand it, nor can I get it to work. However it seems like a really good testing tool.
How do I get the script to read in everything below __DATA__ into a file handle? I tried a few…

capser
- 2,442
- 5
- 42
- 74
5
votes
1 answer
How to subclass IO::Handle to properly get a low level file handle without having a file or memory?
I have an app which accesses a PostgreSQL database and needs to read some large binary data out of it depending on some needed processing. This might be hundreds of MB or even some GB of data. Please no discussion about using file systems instead or…

Thorsten Schöning
- 3,501
- 2
- 25
- 46