develooper Front page | perl.perl5.porters | Postings from March 2000

[BUG] can't exit 0 from CHECK{}

Thread Next
From:
Tom Christiansen
Date:
March 28, 2000 07:02
Subject:
[BUG] can't exit 0 from CHECK{}
Message ID:
3146.954255727@chthon
From a CHECK{}, you cannot exit(0).  You may exit !0, but not 0.
If you put this in /tmp/a and run it:

    #BEGIN { warn "testing exit from BEGIN"; exit }
    #BEGIN { warn "testing exit N from BEGIN"; exit 1 }

    #INIT { warn "testing exit from INIT"; exit }
    #INIT { warn "testing exit N from INIT"; exit 2 }

    CHECK { warn "testing exit from CHECK"; exit }
    #CHECK { warn "testing exit N from CHECK"; exit 3 }

    #END { warn "testing exit from END"; exit }
    #END { warn "testing exit N from END"; exit 4 }

    print "i am now the main program\n";
    warn "testing exit 5 from main";
    exit 5;

    die "XXX";

You will get:

    % perl /tmp/a
    testing exit from CHECK at /tmp/a line 7.
    i am now the main program
    testing exit 5 from main at /tmp/a line 14.
    Exit 5

If you switch the comment on the two CHECKs, you get

    % perl /tmp/a
    testing exit N from CHECK at /tmp/a line 8.
    Exit 3

--tom

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