Sponsored Content
Top Forums Shell Programming and Scripting Perl: Opening a filehandle but not getting anything back from it Post 302224046 by buffoonix on Tuesday 12th of August 2008 05:50:51 AM
Old 08-12-2008
Hi Smiling Dragon,

glad you could fix that.

Because my eyes got too distracted I copied and pasted your buggy and fixed versions of the second sub and made a diff
Code:
$ diff bla?
9c9
<                         open(SYSMAN, "$sysman|") || return;
---
>                         open(SYSMAN, "$sysman|");
15c15
<                         $sysmanhandle=shift @sysmanhandles;
---
>                         my $sysmanhandle=shift @sysmanhandles;
23d22
<                         close($sysmanhandle);
24a24
>                         close($sysmanhandle);

I think the removal of return on a failed open didn't make the difference
(though I would assume it to be better style after all if you couldn't reconcile with a die on that condition).
However, what I think made the difference was the explicit lexical redeclaration of $sysmanhandle.

I also would have advised to set the autoflush before the reading loop by squeezing in a
Code:
$|++;

hadn't you come up with the solution.

Sorry, for ill-advising you on presumed redundancy of quotes.
Even if I were right it is always better to be explicit.
I just was thinking about a talk I once attended at a Perl conference or workshop held by
Mark Jason Dominus (author of Higher Order Perl)
where he ranted about cave men dwellers' useless quoting voodoo.
He there brought onto my radar the wonderful Deparse module
to check what Perl really makes out of your expressions.
Have a look at
Code:
$ perldoc B::Deparse

in case you haven't come about it yet.
Quote:
I'll give that a try but I suspect I'll hit trouble as I'm obliged to use a fairly old perl (old system that's not to be fiddled with more than absolutely necessary).
The lexical vars as valid file handles to an open call became available as of Perl 5.6.0
if I remember correctly.
If your Perl is that old or even older then you should really consider an update Smilie
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Opening Perl

I have gone to /usr/bin/ and click on perl but notting happens.also notting happens when i click on c/c++ or any other program whats wrong ? (2 Replies)
Discussion started by: perleo
2 Replies

2. Shell Programming and Scripting

perl: howto print to screen & filehandle

Hello, I need to print messages both to screen and to file handle in perl , like tee does in unix . Any suggestions ? Thanks (2 Replies)
Discussion started by: Alalush
2 Replies

3. Shell Programming and Scripting

Opening Files and checking contents in Perl

Hi All, I need some expert help in performing the following in Perl. I have a code below but it doesn;t seem to work. Can any expert give me some advice? Below are the requirements 1) Open numerous files assigned to an array @FILES. Note that the files are always named with the term... (7 Replies)
Discussion started by: Raynon
7 Replies

4. Shell Programming and Scripting

Opening Mulitple files using For loop in Perl

Hi All, I have a total of ten file to open in the Perl script and i am using a for loop to open each file and capture some strings inside each file. Unfortunately, i encounter the below syntax error. I think there should be something wrong with this term reports_${counting}_${_}.txt but i do... (4 Replies)
Discussion started by: Raynon
4 Replies

5. Shell Programming and Scripting

How to call a shell script from a perl module which uses Filehandle to login

Hi Guru's, Pardon me for the breach of rules..... I have very little knowledge about Shell Programming and Scripting hope you guys help me out of this troble I have very little time hence could not find the right way to direct my queries. coming to the problem I need to call a... (2 Replies)
Discussion started by: saikrishna_tung
2 Replies

6. Shell Programming and Scripting

Perl-opening a file then copying files

Good morning guys!! Im still practicing with Perl and now Im trying to open a file, and copy its contents to another file. Them I want to remeove the information out of the orginal file after it is copied over. The flow should be messages-->messages1-->messages2. Kind of like a log... (1 Reply)
Discussion started by: bigben1220
1 Replies

7. Programming

Error:readline() on closed filehandle Perl

Hi, i have run the below perl code and i am getting an error Error:readline() on closed filehandle OR at run.pl line 31. CODE: =========================================== open OR,$ARGV; while (<OR>) { # find the batch date next if length $_ < 3; # BLANK LINE # last if $. > 120; #... (3 Replies)
Discussion started by: pspriyanka
3 Replies

8. UNIX for Dummies Questions & Answers

Opening a file in perl

Hi I need to open a file if a condition(for example a if a regular expression) is met. How do i do this ? open (file) if (some regex)..... (3 Replies)
Discussion started by: manutd
3 Replies

9. Shell Programming and Scripting

perl FileHandle Closure during after unlock

Hi we have one function which is used to append data the file in exclusive lock mode in aperl script. This script is executed by multiple threads at the same time. accessing the same file.this script runs throught the day. sometimes the file2.txt size is getting reduced. for eg from 10 M... (1 Reply)
Discussion started by: Shahul
1 Replies

10. Shell Programming and Scripting

Printing a message in file without opening it in perl

Hello friends, i have a perl script as below ... for (0 ..$#values) { ##want to print some message here in Report.txt file print `find /abc/xyz/pqr/$values" -type f -ls` >> Report.txt } I am able to get output of print `find /abc/xyz/pqr/$values" -type f -ls` >> Report.txt in... (2 Replies)
Discussion started by: harpal singh
2 Replies
apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR:UserlContributed Perl Doapache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::PerlIO(3)

NAME
APR::PerlIO -- Perl IO layer for APR Synopsis # under mod_perl use APR::PerlIO (); sub handler { my $r = shift; die "This Perl build doesn't support PerlIO layers" unless APR::PerlIO::PERLIO_LAYERS_ARE_ENABLED; open my $fh, ">:APR", $filename, $r->pool or die $!; # work with $fh as normal $fh close $fh; return Apache2::Const::OK; } # outside mod_perl % perl -MAPR -MAPR::PerlIO -MAPR::Pool -le 'open my $fh, ">:APR", "/tmp/apr", APR::Pool->new or die "$!"; print $fh "whoah!"; close $fh;' Description "APR::PerlIO" implements a Perl IO layer using APR's file manipulation API internally. Why do you want to use this? Normally you shouldn't, probably it won't be faster than Perl's default layer. It's only useful when you need to manipulate a filehandle opened at the APR side, while using Perl. Normally you won't call open() with APR layer attribute, but some mod_perl functions will return a filehandle which is internally hooked to APR. But you can use APR Perl IO directly if you want. Prerequisites Not every Perl will have full "APR::PerlIO" functionality available. Before using the Perl IO APR layer one has to check whether it's supported by the used APR/Perl build. Perl 5.8.x or higher with perlio enabled is required. You can check whether your Perl fits the bill by running: % perl -V:useperlio useperlio='define'; It should say define. If you need to do the checking in the code, there is a special constant provided by "APR::PerlIO", which can be used as follows: use APR::PerlIO (); die "This Perl build doesn't support PerlIO layers" unless APR::PerlIO::PERLIO_LAYERS_ARE_ENABLED; Notice that loading "APR::PerlIO" won't fail when Perl IO layers aren't available since "APR::PerlIO" provides functionality for Perl builds not supporting Perl IO layers. Constants "APR::PerlIO::PERLIO_LAYERS_ARE_ENABLED" See Prerequisites. API
Most of the API is as in normal perl IO with a few nuances listed in the following sections. META: need to rework the exception mechanism here. Current success in using errno ($!) being set (e.g. on open()) is purely accidental and not guaranteed across all platforms and functions. So don't rely on $!. Will use "APR::Error" for that purpose. "open" Open a file via APR Perl IO layer. open my $fh, ">:APR", $filename, $r->pool or die $!; arg1: $fh ( GLOB filehandle ) The filehandle. arg2: $mode ( string ) The mode to open the file, constructed from two sections separated by the ":" character: the first section is the mode to open the file under (>, <, etc) and the second section must be a string APR. For more information refer to the open entry in the perlfunc manpage. arg3: $filename ( string ) The path to the filename to open arg4: $p ( "APR::Pool" ) The pool object to use to allocate APR::PerlIO layer. ret: ( integer ) success or failure value (boolean). since: 2.0.00 "seek" Sets $fh's position, just like the "seek()" Perl call: seek($fh, $offset, $whence); If $offset is zero, "seek()" works normally. However if $offset is non-zero and Perl has been compiled with with large files support ("-Duselargefiles"), whereas APR wasn't, this function will croak. This is because largefile size "Off_t" simply cannot fit into a non-largefile size "apr_off_t". To solve the problem, rebuild Perl with "-Uuselargefiles". Currently there is no way to force APR to build with large files support. since: 2.0.00 C API
The C API provides functions to convert between Perl IO and APR Perl IO filehandles. META: document these See Also mod_perl 2.0 documentation. The perliol(1), perlapio(1) and perl(1) manpages. Copyright mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. Authors The mod_perl development team and numerous contributors. perl v5.16.2 2011-02-07 apache_mod_perl-108~358::mod_perl-2.0.7::docs::api::APR::PerlIO(3)
All times are GMT -4. The time now is 08:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy