Questions tagged [filehandle]

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.

407 questions
2
votes
1 answer

Referencing a FileHandle as an Array

Given that I have a 4GB file I need to process, is there a way in Perl where I can reference a filehandle like an array without copying it into an actual array/memory? Something like: open (LOG, "less file.txt |"); my @reference = \; print…
Funguf
  • 23
  • 2
2
votes
3 answers

Infile Handle in C++ (ala __DATA__ in Perl)

Does C++ have access to infile data through a filehandle? For example the typical idiom in Perl is: while () { chomp; # do sth with $_ } __DATA__ Foo Bar What's the way to do that in C++ ?
neversaint
  • 60,904
  • 137
  • 310
  • 477
2
votes
1 answer

Syntax error using a filehandle stored in a hash value

I am trying, with a one-liner, to write lines read from an input source to different files according to the contents of a field of the line itself. My method was to use a hash to store the filehandles in order to avoid opening the same file multiple…
2
votes
1 answer

Swift. How to append text line to top of file.txt?

I am implementing a small logger, in which I am writing to a TXT file. I wanted the last event to be at the top of the file but I'm having trouble getting this to work. All examples on the internet are using "fileHandle.seekToEndOfFile()" to write…
Tiago Mendes
  • 4,572
  • 1
  • 29
  • 35
2
votes
4 answers

What does *PIPER mean in Perl?

I need some help understanding the following Perl code snippet. I have the following two questions. 1. What does local *PIPER mean? Even though I've done some Perl programming before the local * syntax is new to me. Is it a pointer? 2. What is the…
None
2
votes
1 answer

How do I set a default FileHandle attribute with moose

You may infer from the question that this is my first Moose class. How do I set an attribute FileHandle to *STDOUT? This doesn't work. has 'output' => ( is => 'rw', isa => 'FileHandle', default => sub { openhandle(*STDOUT) } ); The…
Erik Bennett
  • 1,049
  • 6
  • 15
2
votes
1 answer

Allow line editing when reading input from the command line

I already know how to get the input from user keyboard. I can use the readLine() method or let input = FileHandle.standardInput let inputData = input.availableData var text = String(data: inputData, encoding: .utf8) But the two methods get…
Fab
  • 816
  • 8
  • 17
2
votes
1 answer

How to get back to the beginning of a file in a perl one-liner?

After going through a file once, I would like to go back to the beginning of the file and remove entries based on my original pass through the file, but I do not know how to go back to the beginning of the file. I have the name of the input file to…
2
votes
1 answer

Index distance to FileHandle pointer and characters encoding in Swift 4

I have this function to return (and seek) a FileHandle pointer at a specific word: func getFilePointerIndex(atWord word: String, inFile file: FileHandle) -> UInt64? { let offset = file.offsetInFile if let str = String(data:…
Ali_Habeeb
  • 205
  • 2
  • 9
2
votes
2 answers

How to read a line from a filehandle in a hashref

I have a handle to a socket in an hashref: $self->{socket}. I want to read from it using $line = <$self->{socket}>, but I get a syntax error. Now, I know that print {$self->{socket}} "Hello"; Will take care of printing, but $line = <…
Vic K
  • 135
  • 7
2
votes
2 answers

Return file handle from subroutine and pass to other subroutine

I am trying to create a couple of functions that will work together. getFH should take in the mode to open the file (either > or < ), and then the file itself (from the command line). It should do some checking to see if the file is okay to open,…
Kyle Weise
  • 869
  • 1
  • 8
  • 29
2
votes
2 answers

Using a separate file handle to read a temporary file created using File::Temp

I created a temporary file using File::Temp and added some data to it. At some other point of time, I would like to read the temporary file, using a separate file handle (seek method works). Following is the code snippet. #!usr/local/bin/perl use…
aman
  • 365
  • 3
  • 13
2
votes
4 answers

Problems when writing to file with FileHandler

I have a code that looks like this: let fileName = "name.txt" let fileURL = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent(fileName) try! "".write(to: fileURL, atomically: true, encoding: String.Encoding.utf8) let fileHandle =…
MegaManX
  • 8,766
  • 12
  • 51
  • 83
2
votes
6 answers

How to get the name of a file from a file handle in Windows using C?

I'm trying to retrieve a file name from a given file handle. I've seen that GetFileInformationByHandle could be useful, but the structure it returns does not contain any file name information…
Julio
  • 21
  • 1
  • 2
2
votes
1 answer

Python script to move files to either a train dir or test dir

I am the moment making a python script capable of diving my data into either a train dir or test dir. I provide the script with an ratio, which says what the ratio between train/test should be, an according to that should files randomly be moved…
mom
  • 23
  • 3