Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by Anonymous Monk
on Feb 03, 2013 at 08:19 UTC ( #1016803=note: print w/ replies, xml ) Need Help??


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

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


Comment on Re^5: help with error 'readline() on unopened filehandle'
Download Code
Replies are listed 'Best First'.
Re^6: help with error 'readline() on unopened filehandle'
by Anonymous Monk on Feb 03, 2013 at 08:37 UTC
    Also, 3 argument open is safer than 2 argument open -- sure you hardcoded the filename, but the OP hasn't
Re^6: help with error 'readline() on unopened filehandle'
by Anonymous Monk on Feb 03, 2013 at 08:36 UTC
      that's my advice for you ... read a ruby tut. get a hair cut and a JOB!

        that's my advice for you ... read a ruby tut. get a hair cut and a JOB!

        die

      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 >:(
        You are not excused. If you're going to correct folks, be sure to know what you're talking about first

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (17)
As of 2015-07-28 17:04 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 (258 votes), past polls