Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: help with error 'readline() on unopened filehandle'

by bhargavkanakiya (Initiate)
on Feb 03, 2013 at 08:10 UTC ( #1016800=note: print w/ replies, xml ) Need Help??


in reply to Re^3: help with error 'readline() on unopened filehandle'
in thread help with error 'readline() on unopened filehandle'

i understood that and updated the code as

... open my $MYFILE , "<$filename" || "Can't open the output file!"; ...

then the error changed to 'readline() on closed filehandle $MYFILE' even though i have not closed the file. this is the first code that i've written using perl and i am completely new to it. any help is appreciated. thanks.


Comment on Re^4: help with error 'readline() on unopened filehandle'
Download Code
Re^5: help with error 'readline() on unopened filehandle'
by Anonymous Monk on Feb 03, 2013 at 08:19 UTC
    Don't put a '$' on your file handle. Here's how you open and read from a file:
    $ cat file.txt line one line two line three $ cat open_and_read.pl #!/usr/bin/perl -w use strict; # usually one does not put a $ on a filehandle variable open ( MYFILE, "<file.txt" ) or die "could not be opening the file now + :$!\n"; while ( my $line = <MYFILE> ) { print $line; } close ( MYFILE ); $ ./open_and_read.pl line one line two line three
        Well EXCUSE ME!!!!!! Back in my day sonny we didn't put '$' on our filehandle variables and LIKE IT! If you are going in for new fangled paradigms you might as well code in ruby >:(
        that's my advice for you ... read a ruby tut. get a hair cut and a JOB!
      Also, 3 argument open is safer than 2 argument open -- sure you hardcoded the filename, but the OP hasn't
Re^5: help with error 'readline() on unopened filehandle' (precedence, or not ||)
by Anonymous Monk on Feb 03, 2013 at 08:21 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1016800]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (12)
As of 2015-07-07 13:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls