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

RE: nonzero $! value after closing a pipe normally

Thread Previous | Thread Next
From:
gungor_o
Date:
February 6, 2002 05:05
Subject:
RE: nonzero $! value after closing a pipe normally
Message ID:
18898706268C5147A4C58A423EEB332D59EC8A@kf1srv1

Thank you Shawn.  I will use other alternatives for error checking.

OKI

		-----Original Message-----
		From:	Shawn [mailto:shawn@baimc.com]
		Sent:	Wednesday, February 06, 2002 2:22 PM
		To:	gungor_o@kocfinans.com.tr; beginners@perl.org
		Subject:	Re: nonzero $! value after closing a pipe
normally


		----- 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 | 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