in reply to Best way to handle readline errors?

Update:

I misread the question. So this answer does not apply. I apologize for all the noise I introduced with my answers

Regards

lin0

Hi jrw,

did you try the following?

while ( defined($data = <$fh>) ) { # do something ... # usually: chomp($data); }

Cheers!

lin0

Replies are listed 'Best First'.
Re^2: Best way to handle readline errors?
by jrw (Monk) on Nov 11, 2006 at 01:13 UTC
    That won't tell me if I had an error or if I reached EOF. I want to distinguish those two cases.

      Update

      I just want to withdraw my answer to the question. I want to apologize to the OP for not answering the question and adding noise in the process. On my defense, I wanted to help but I guess I was too tired to think clearly

      All the best

      lin0

      Hi jrw,

      maybe you are interested in something like this piece of code I found and adapted from the perldoc for readline

      for (;;) { undef $!; unless (defined( $data = <$fh> )) { die $! if $!; last; # reached EOF } # do what you need to do with your data # like: # chomp($data); # ... }

      I hope this helps

      lin0
        Did you actually read what he posted?