Error checking reads

D

Dave Saville

I was taught to check *anything* that produced a return code. In I
think all perl programs I have ever seen I see opens followed by "or
die ....."

But how does one check the <> operator? I suppose one could code

my @a = <$somehandle> or die .........
and
my $a = <$somehandle> or die ...........

but what about

while ( <$somehandle> )
?

TIA
 
D

Dave Saville

Thanks Tad
A rather obvious exception is the return value from print().

Once you have a properly opened filehandle, about the only thing
that can go wrong is "file system full", and if that happens, you
won't need your little Perl program to tell you that something is
wrong, because the whole 'puter will stop working. :)




Unless

use autodie;




Once you know that the named version of the <> operator is readline(),
then you can just read its docs for that :)

I do now :)
perldoc -f readline


If readline encounters an operating system error, C<$!> will be set
with the
corresponding error message. It can be helpful to check C<$!> when
you are
reading from filehandles you don't trust, such as a tty or a socket.

Yes, it was sockets that brought the whole thing up.

Thanks again.
 
P

Peter Makholm

Tad McClellan said:
A rather obvious exception is the return value from print().

Once you have a properly opened filehandle, about the only thing
that can go wrong is "file system full", and if that happens, you
won't need your little Perl program to tell you that something is
wrong, because the whole 'puter will stop working. :)

Except for filehandles you don't, such as a pipe or a socket.

Also the whole 'puter will not stop working just because you have filled
one of multiple filesystems. I have written a few batch processing
systems with seperate scratch space filesystems just for data.

//Makholm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top