Error checking reads

Discussion in 'Perl Misc' started by Dave Saville, Jan 28, 2012.

  1. Dave Saville

    Dave Saville Guest

    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
    Dave Saville, Jan 28, 2012
    #1
    1. Advertising

  2. Dave Saville

    Dave Saville Guest

    On Sat, 28 Jan 2012 15:08:43 UTC, Tad McClellan <>
    wrote:

    Thanks Tad

    > Dave Saville <> 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
    Dave Saville, Jan 28, 2012
    #2
    1. Advertising

  3. Tad McClellan <> writes:

    > Dave Saville <> 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
    Peter Makholm, Jan 28, 2012
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. John Timney \(Microsoft MVP\)

    ASPX reads Word doc

    John Timney \(Microsoft MVP\), Apr 2, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    313
    =?Utf-8?B?TWFyaw==?=
    Apr 2, 2004
  2. Daniel
    Replies:
    4
    Views:
    2,778
    Adam Maass
    Sep 11, 2003
  3. Mark McKay

    Socket reads not blocking

    Mark McKay, Oct 3, 2003, in forum: Java
    Replies:
    2
    Views:
    429
    Gordon Beaton
    Oct 3, 2003
  4. Jan Goormans

    linking error with : reads c compiler from rigel

    Jan Goormans, May 1, 2004, in forum: C Programming
    Replies:
    3
    Views:
    287
    Richard Bos
    May 3, 2004
  5. Simon Gare
    Replies:
    0
    Views:
    382
    Simon Gare
    Jul 30, 2006
Loading...

Share This Page