Questions tagged [perl-io]

Input/Output in Perl

Perl Input/Output modules and methods.

29 questions
46
votes
12 answers

What's the best way to open and read a file in Perl?

Please note - I am not looking for the "right" way to open/read a file, or the way I should open/read a file every single time. I am just interested to find out what way most people use, and maybe learn a few new methods at the same time :)* A very…
BrianH
  • 7,932
  • 10
  • 50
  • 71
8
votes
4 answers

Read unbuffered data from pipe in Perl

I am trying to read unbufferd data from a pipe in Perl. For example in the program below: open FILE,"-|","iostat -dx 10 5"; $old=select FILE; $|=1; select $old; $|=1; foreach $i () { print "GOT: $i\n"; } iostat spits out data every 10…
Brad
  • 11,262
  • 8
  • 55
  • 74
8
votes
1 answer

Making an old library work with Perl XS and PerlIO

I am rather an XS beginner and I am looking into changing an existing XS module which uses a 15+ year old underlying C library heavily (in fact the module is basically just glue to this library). The problem is that I would like to be able to use…
PLK
  • 389
  • 2
  • 13
7
votes
3 answers

How can I redirect output of die function to a file in Perl?

I want to redirect the die messages to a separate file so that I can compare that file later to determine what went wrong. But this code gives me errors: $ cat test.pl use strict; use warnings; my $log = "msglog.log"; die $log "DEAD$!"; $ perl…
Lazer
  • 90,700
  • 113
  • 281
  • 364
7
votes
1 answer

Getting exceptions from IO::File?

The IO::File, IO::Socket::INET modules have some advantages over directly using perl's built-in IO functions, such as having explicit syntax to flush a handle. However, they seem to have some disadvantages over the built-in IO functions. For…
John Dough
  • 400
  • 3
  • 9
7
votes
2 answers

Why is this XS code that returns a PerlIO* leaky?

I am trying to write some XS code that exposes pieces a library to Perl code as a stream interface that can be written to. The get_stream function below is supposed to be a constructor that prepares and returns a PerlIO object. I figured that I only…
hillu
  • 9,423
  • 4
  • 26
  • 30
7
votes
2 answers

Can I get a handle to - source?

It looks like there is a symbol in main called '_<-' (without the quotes) in the same fashion as the other things that look like they could be handles: '_
Axeman
  • 29,660
  • 2
  • 47
  • 102
6
votes
1 answer

Non-determinism in encoding when using open() with scalar and I/O layers in Perl

For several hours now I am fighting a bug in my Perl program. I am not sure if I do something wrong or the interpreter does, but the code is non-deterministic while it should be deterministic, IMO. Also it exhibits the same behavior on ancient…
Palec
  • 12,743
  • 8
  • 69
  • 138
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
4
votes
0 answers

embedded perl in C, perlapio - interoperability with STDIO

I just realized, that the PerlIO layer seems to do something more than just (more or less) easily wrap the stdio.h-functions. If I try to use a file-descriptor resolved via PerlIO_stdout() and PerlIO_fileno() with functions from stdio.h, this…
Semonit
  • 379
  • 3
  • 14
3
votes
1 answer

perl open() always returns the PID of the sh instead of the underlying program

I have to kill a program that I am opening via $pid = open(FH, "program|") or $pid = or open(FH, "-|", "program") However, the program (mosquittto_sub, to be specific) still lingers around in the background, because open is returning the PID of the…
3
votes
3 answers

Monitoring external process: Exit when STDOUT matches pattern

I'm running a system command and waiting for output matching a specific pattern, e.g: open(my $fh, '-|', 'echo line 1; sleep 20; echo line 2'); while (<$fh>) { print && last if /1/; } close $fh; This will print line 1 and leave the loop but…
RobEarl
  • 7,862
  • 6
  • 35
  • 50
3
votes
3 answers

How to create a new file in Perl?

I've some values stored in the variables $a,$b,$c. Now I've to load these values into new file (create file & load). I'm new to Perl, how can I do it?
Jackie James
  • 785
  • 8
  • 15
  • 28
2
votes
1 answer

perlapio - PerlIO_findFILE() works but sets errno to "illegal seek" (ESPIPE 29)

This issue is more or less related to embedded perl in C, perlapio - interoperability with STDIO which I think I have solved for the Windows environment. I will post a complete solution if this new issue is solved too. In the linked…
Semonit
  • 379
  • 3
  • 14
2
votes
2 answers

IO::Handle to get and unget unicode characters

I think I've run into a problem with Unicode and IO::Handle. It's very likely I'm doing something wrong. I want to get and unget individual unicode characters (not bytes) from an IO::Handle. But I'm getting a surprising…
Michael
  • 8,446
  • 4
  • 26
  • 36
1
2