develooper Front page | perl.beginners | Postings from February 2002

Re: nonzero $! value after closing a pipe normally

Thread Previous
From:
Shawn
Date:
February 6, 2002 04:24
Subject:
Re: nonzero $! value after closing a pipe normally
Message ID:
02b401c1af08$e6c2cd90$d800a8c0@work

----- Original Message -----
From: <gungor_o@kocfinans.com.tr>
To: <beginners@perl.org>
Sent: Wednesday, February 06, 2002 6:07 AM
Subject: nonzero $! value after closing a pipe normally

>Hi all,
>
>I have a code part like the following.
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>open MYPROFILE, "cat mytxtfile |";

Why not say:
  open MYPROFILE, "cat mytextfile |" or pr_my_error_routine “close error in MYPROFILE with $!\n”;

Then have the die or exit in the pr_my_error_routine...

or

  my $status=open MYPROFILE, "cat mytxtfile |";
  unless($status) {
    pr_my_error_routine “close error in MYPROFILE with $!\n”;
  }

  You can't rely on $! not to be holding an 'error' already that you haven't checked for...or, so
has been my experience.

Shawn

>if ( $! != 0 ) {
>  print "h1 -> $!\n";
>}
>while (<MYPROFILE>) {
>next if /^(tcp|udp)/;
>print;
>}
>close MYPROFILE or die "bad: $! $?";
>
>if ( $! != 0 ) {
>  pr_my_error_routine “close error in MYPROFILE with $!\n”;
>}
><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
>
>As a beginner user, I try to use my error routine instead of die method
>after a simple check
>of last command exit code.
>
>Here if I use a text file
>     open MYPROFILE, "mytxtfile "
>instead of a pipe it works. My problem is non-zero value after close of a
>pipe. die works (I mean it doesn’t die as expected), but I can’t use if ( $!
>!= 0 )  … instead of die.
>
>TIA,
>
>OKI


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About