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

nonzero $! value after closing a pipe normally

Thread Next
From:
gungor_o
Date:
February 6, 2002 04:07
Subject:
nonzero $! value after closing a pipe normally
Message ID:
18898706268C5147A4C58A423EEB332D59EBFC@kf1srv1
Hi all,

I have a code part like the following.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
open MYPROFILE, "cat mytxtfile |";
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 Next


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