in reply to Re: Perl open pipe exiting early
in thread Perl open pipe exiting early

Hi,

Thanks for the response. Will the use of fudge only work though if I know the failure point? My script "fails" when the the script thinks that my file handle's reference count has reached zero before it should have done. I am not sure how I can catch this issue using fudge. Or should i just run the fudge procedure every time and it will eventually catch the information I need?

if (my $pid = open(...) { while(<FH>) { } fudge(): } else{ }

Thanks

(The issue is made difficult by the fact that I can't reproduce the issue locally....but multiple users are seeing it. Makes debugging difficult!)

Replies are listed 'Best First'.
Re^3: Perl open pipe exiting early
by Anonymous Monk on Apr 03, 2015 at 23:40 UTC

    Thanks for the response. Will the use of fudge only work though if I know the failure point?

    Use it in every place there can be a failure ... open or Fudge() ... close or Fudge() ... even readline or Fudge();

    while ( ! eof($fh) ) { defined( $_ = <$fh> ) or die Fudge("readline \$fh"); ... }

    Heck, even enhance it to sparkle some $? extras

    sub Fudge { my $pipe = $?; use Errno(); my $msg = join qq/\n/, "Error @_", map { " $_" } int( $! ) . q/ / . $!, int( $^E ) . q/ / . $^E, grep( { $!{$_} } keys %! ) ; $^E = $! = $pipe; $msg .= join qq/\n/, map { " $_" } "\n #", #~ int( $! ) . q/ / . $!, #~ int( $^E ) . q/ / . $^E, 'status($?) '.( $pipe ), 'subexit($? >>8) '.( $pipe >> 8), 'signal($? & 127) '.( $pipe & 127 ), 'coredump($? & 128) '.( $pipe & 128 ), grep( { $!{$_} } keys %! ), q/ /; return $msg; }