Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Error checking reads

1 view
Skip to first unread message

Dave Saville

unread,
Jan 28, 2012, 10:01:21 AM1/28/12
to
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
--
Regards
Dave Saville

Tad McClellan

unread,
Jan 28, 2012, 10:08:43 AM1/28/12
to
Dave Saville <da...@invalid.invalid> wrote:

> I was taught to check *anything* that produced a return code.


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. :-)


> In I
> think all perl programs I have ever seen I see opens followed by "or
> die ....."


Unless

use autodie;


> But how does one check the <> operator?


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

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.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.

Dave Saville

unread,
Jan 28, 2012, 11:01:02 AM1/28/12
to
On Sat, 28 Jan 2012 15:08:43 UTC, Tad McClellan <ta...@seesig.invalid>
wrote:

Thanks Tad

> Dave Saville <da...@invalid.invalid> wrote:
>
> > I was taught to check *anything* that produced a return code.
>
>
> 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. :-)
>
>
> > In I
> > think all perl programs I have ever seen I see opens followed by "or
> > die ....."
>
>
> Unless
>
> use autodie;
>
>
> > But how does one check the <> operator?
>
>
> 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.

--
Regards
Dave Saville

Peter Makholm

unread,
Jan 28, 2012, 1:57:40 PM1/28/12
to
Tad McClellan <ta...@seesig.invalid> writes:

> Dave Saville <da...@invalid.invalid> wrote:
>
>> I was taught to check *anything* that produced a return code.
>
>
> 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

Shmuel Metz

unread,
Jan 28, 2012, 9:56:52 PM1/28/12
to
In <slrnji84al...@tadbox.sbcglobal.net>, on 01/28/2012
at 09:08 AM, Tad McClellan <ta...@seesig.invalid> said:

>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. :-)

Perhaps in windoze; certainly not on my machine.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to spam...@library.lspace.org

0 new messages