Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

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

Comment on Re^3: help with error 'readline() on unopened filehandle'
Replies are listed 'Best First'.
Re^4: help with error 'readline() on unopened filehandle'
by bhargavkanakiya (Initiate) on Feb 03, 2013 at 08:10 UTC

    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.

      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 #!/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 ); $ ./ line one line two line three
        Also, 3 argument open is safer than 2 argument open -- sure you hardcoded the filename, but the OP hasn't

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (3)
As of 2016-02-07 10:42 GMT
Find Nodes?
    Voting Booth?

    How many photographs, souvenirs, artworks, trophies or other decorative objects are displayed in your home?

    Results (250 votes), past polls