perl-io

how do I link PerlIO Perl package without “installing it”

天涯浪子 提交于 2019-12-24 22:15:01
问题 I'm trying to add the PerlIO::eol package as part of my project without installing it, this way all dependencies can be packaged with my script without having to reinstall them on each machine. How can I do it for PerlIO::eol I don't understand the structure and where the important files are 回答1: Create a subdirectory inc and move an unpacked PerlIO-eol distro there. Then, use something like this in your project's Build.PL : use Config qw(%config); use Module::Build qw(); my $build = Module:

Monitoring external process: Exit when STDOUT matches pattern

只谈情不闲聊 提交于 2019-12-12 17:03:57
问题 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 won't exit until the external command has completed. How can I allow the script to exit immediately after matching the required output? 回答1: You can send TERM signal to the PID and then close file handle without waiting, my $pid = open(my $fh, '-|', 'echo

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

a 夏天 提交于 2019-12-12 08:46:29
问题 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 test.pl Missing comma after first argument to die function at test.pl line 5, near ""DEAD$!";" Execution of test.pl aborted due to compilation errors. $ I do not want to do a 2> from the caller. Is there someway to redirect them from within the script?

Making an old library work with Perl XS and PerlIO

喜夏-厌秋 提交于 2019-12-08 16:53:54
问题 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 PerlIO string trickery like: open($fh, '<', \$string); and then pass $fh to the XS glue where the library is expecting FILE . The problem is that the XS has: int _parse (entry_ref, filename, file, preserve=FALSE) SV * entry_ref; char * filename; FILE

embedded perl in C, perlapio - interoperability with STDIO

僤鯓⒐⒋嵵緔 提交于 2019-12-06 05:38:32
问题 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 fails. For example: PerlIO* perlStdErr = PerlIO_stderr(); fdStdErrOriginal = PerlIO_fileno(perlStdErr); relocatedStdErr = dup(fdStdOutOriginal); _write(relocatedStdErr, "something", 8); //<-- this fails I've tried this with VC10. The embedded perl

embedded perl in C, perlapio - interoperability with STDIO

淺唱寂寞╮ 提交于 2019-12-04 09:03:08
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 fails. For example: PerlIO* perlStdErr = PerlIO_stderr(); fdStdErrOriginal = PerlIO_fileno(perlStdErr); relocatedStdErr = dup(fdStdOutOriginal); _write(relocatedStdErr, "something", 8); //<-- this fails I've tried this with VC10. The embedded perl program is executed from a different context - so it's not possible to use PerlIO from the context where the

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

霸气de小男生 提交于 2019-12-04 04:02:13
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 test.pl Missing comma after first argument to die function at test.pl line 5, near ""DEAD$!";" Execution of test.pl aborted due to compilation errors. $ I do not want to do a 2> from the caller. Is there someway to redirect them from within the script? wkl Perl's die prints to STDERR so you could redirect STDERR to a file. #!/usr/bin/env perl # the path

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

主宰稳场 提交于 2019-11-26 19:43:45
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 common block of code in my Perl programs is opening a file and reading or writing to it. I have seen so many ways of doing this, and my style on performing this task has changed over the years a few times. I'm just wondering what the best (if there is a best way) method is to do this? I used to open a file like this: my $input_file = "/path/to/my

What&#39;s the best way to open and read a file in Perl?

て烟熏妆下的殇ゞ 提交于 2019-11-26 07:23:13
问题 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 common block of code in my Perl programs is opening a file and reading or writing to it. I have seen so many ways of doing this, and my style on performing this task has changed over the years a few times. I\'m just wondering what the best (if