Error:readline() on closed filehandle Perl


 
Thread Tools Search this Thread
Top Forums Programming Error:readline() on closed filehandle Perl
# 1  
Old 07-07-2011
Error:readline() on closed filehandle Perl

Hi,

i have run the below perl code and i am getting an error

Code:
Error:readline() on closed filehandle OR at run.pl line 31.

CODE:
===========================================
Code:
open OR,$ARGV[2];
while (<OR>) { # find the batch date
next if length $_ < 3; # BLANK LINE
# last if $. > 120; # sample should be good enough
(undef,undef,undef,undef,$date1,$orId,undef)=split(/,/,$_,7);
$dates{$date1}++;
$firstOr ||= $orId;
}
close OR;

===========================================

How to solve this error???

Regards,
priyanka
# 2  
Old 07-07-2011
seems, your file handler is not opened the file itself.

replace your open statement and run the code

Code:
 
open OR, $ARGV[2] or die "can't open $ARGV[2]: $!\n";

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 07-07-2011
Are you checking if the file you're trying to open actually exists, and that you have read permissions on it?

Some thumb rules I use that can be applied here:
  • use strict;
  • use warnings;
  • 3 Parameter open >> any other form
  • Always check $! and $@ after something error prone
  • Never rely on $_ unless you know what you're doing
These 2 Users Gave Thanks to pludi For This Post:
# 4  
Old 07-07-2011
basic perl code-

Thanks pludi, itkamaraj for helping me :-)


the problem is file was not present

Last edited by pspriyanka; 07-07-2011 at 07:49 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Connection closed by host error in rhel 6 Linux

Hi All, I am new to Redhat Enterprise Linux 6 version. I am facing an issue with my lab server which is having RHEL6 lab1:root> uname -a Linux lab1 2.6.32-358.18.1.el6.x86_64 #1 SMP Fri Aug 2 17:04:38 EDT 2013 x86_64 x86_64 x86_64 GNU/Linux I am getting this error for every 18 minutes 30... (0 Replies)
Discussion started by: go2suresh1979
0 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. Programming

Readline programming

Hi, I am new to using readline library to my application. Please I want to no how to write code for command line switches(options), i.e when i press tab the option of command as to change. eg: ls -a ls -d ...so on ls as many options, here i want options to be completed using tab ... (9 Replies)
Discussion started by: vanid
9 Replies

4. Shell Programming and Scripting

Readline Formatting

Hi All, I have a function that loops through an XML file line by line and spits it the content out to a new file (sometimes certain lines need changing). This all works fine, however the formatting of the original XML is not kept. for example:- <?xml version="1.0"?> <mysqldump>... (3 Replies)
Discussion started by: robfwauk
3 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. Programming

Readline problems

I'm having problems with libreadline. When I write text longer than the current line, the text wraps back to the beginning of the line rather than to the next line. Also, when I use the arrow keys to edit something in that beginning part, it won't display at all (so I can edit only if I remember... (5 Replies)
Discussion started by: CRGreathouse
5 Replies

7. Shell Programming and Scripting

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

I have two perl functions defined, both run a set of shell commands on some somplied data and return hashs of the resulting parsed output from these shell commands. One works, one doesn't and I can't seem to see why. It's driving me insane :mad: The working one: sub getcellstatus { ... (8 Replies)
Discussion started by: Smiling Dragon
8 Replies

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

9. Programming

Change FileHandle

Hello, I currently have a system that is running and writing to a log file. Every month I run a rollLogs script that moves this file to a different location and creates a new file in the original location. The service that is writing to this log is running when i run this script and it still... (3 Replies)
Discussion started by: findandy
3 Replies

10. UNIX for Dummies Questions & Answers

no shell connection closed error

Hi, I have created some users on my new enviroment on sun solaris in the aptempt to create a .profile which I did. I must have done something wrong because when I try to connect to one of this users it says:no shell, connection closed. The only thing I can think is that in my .profile I inserted... (2 Replies)
Discussion started by: giulianob
2 Replies
Login or Register to Ask a Question