Perl: Opening a filehandle but not getting anything back from it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: Opening a filehandle but not getting anything back from it
# 8  
Old 08-13-2008
Quote:
Originally Posted by buffoonix
Because my eyes got too distracted I copied and pasted your buggy and fixed versions of the second sub and made a diff
I should have thought of that - good idea! Smilie
Quote:
Originally Posted by buffoonix
Code:
<                         open(SYSMAN, "$sysman|") || return;
---
>                         open(SYSMAN, "$sysman|");
15c15

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).
Tried adding || return back in, still works (so I've kept it in).
Quote:
Originally Posted by buffoonix
Code:
<                         $sysmanhandle=shift @sysmanhandles;
---
>                         my $sysmanhandle=shift @sysmanhandles;
23d22

However, what I think made the difference was the explicit lexical redeclaration of $sysmanhandle.
Tried adding and removing the 'my' flag and it made no difference (so I've left it in).
Quote:
Originally Posted by buffoonix
Code:
<                         close($sysmanhandle);
24a24
>                         close($sysmanhandle);

I'm assuming this is just a false hit caused by a different line number.

So that leaves me still wondering what I did wrong the first time but not the second... It feels like an unprintable character or something but I've pulled out the old broken version and stupidly deleted it so I can't go and find out.
Quote:
Originally Posted by buffoonix
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.
Tha's a good point, I've not been paying much attention to my buffers. I might go back through the whole thing and make a concious decision in each case. The close should clear most things but best to be safe Smilie
Quote:
Originally Posted by buffoonix
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.
I see some loopy quoting myself and have been a culpret too from time to time Smilie
Quote:
Originally Posted by buffoonix
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.
Will do so, that sounds really useful for optimising some of my more complex strings.
Quote:
Originally Posted by buffoonix
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
5.005_03 - like I said, pretty old Smilie I could potentially upgrade but I'm trying to make this thing work on an existing production system without having to install much else.
I'll avoid going to a sensible version of perl as long as I can.
# 9  
Old 08-16-2008
Quote:
5.005
That's really legacy stuff but you can be glad it's not even 5.004.
However, I can see your constraints.
I also have many systems where I am not supposed to install anything
even if it was for the better.

I've just come back from YAPC::EU 2008 where I got many inspirations,
foremost of course to move to Perl 5.10 which unanimously was considered the best Perl ever and as Damian put it, already feels like 10% of Perl 6.
Until we get Perl 6 which should be out by Xmas - we can't yet tell which Xmas.
But then every day will be like Xmas.

Quote:
I got the idea from my own insane musings then found an example on PerlMonks - The Monastery Gates
I think that's the best you can do because at Perl Monks you will find many of the world's best Perl hackers.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question