develooper Front page | perl.perl5.porters | Postings from September 2011

Re: [perl #100364] exit doesn't match its documentation

Thread Previous | Thread Next
From:
Abigail
Date:
September 29, 2011 09:25
Subject:
Re: [perl #100364] exit doesn't match its documentation
Message ID:
20110929162527.GE10307@almanda
On Thu, Sep 29, 2011 at 06:38:22AM -0700, Nicholas Clark wrote:
> # New Ticket Created by  Nicholas Clark 
> # Please include the string:  [perl #100364]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=100364 >
> 
> 
> 
> This is a bug report for perl from nick@ccl4.org,
> generated with the help of perlbug 1.39 running under perl 5.15.3.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> I don't think that I'm being stupid here.
> 
> The docs say:
> 
> =item exit
> 
> Evaluates EXPR and exits immediately with that value.    Example:
> 
>     $ans = <STDIN>;
>     exit 0 if $ans =~ /^[Xx]/;
> 
> 
> And C<1 == 1> is an expression? Right?
> 
> $ perl -wle 'exit 1 == 1'; echo $?
> Useless use of numeric eq (==) in void context at -e line 1.
> 1
> $ perl -wle 'exit 1 == 0'; echo $?
> Useless use of numeric eq (==) in void context at -e line 1.
> 1
> 
> 
> adding parentheses forces the issue;
> 
> $ perl -wle 'exit(1 == 1)'; echo $?
> 1
> $ perl -wle 'exit(1 == 0)'; echo $?
> 0
> 
> 
> I'm aware of the Advice from Klortho. Particularly:
> 
> #11943 Ah yes, and you are the first person to have noticed this bug since 1987.  Sure. 
> 
> 
> But it does seem to be an inconsistency between the documentation and the
> implementation. I assume that the implementation trumps the documentation
> here, given that it's been constant as far back as I can test:
> 
> $ ~/Sandpit/5000/bin/perl -lwe 'exit 1 == 1'; echo $?
> Useless use of numeric eq in void context at -e line 1.
> 1
> $ ~/Sandpit/5000/bin/perl -lwe 'exit 1 == 0'; echo $?
> Useless use of numeric eq in void context at -e line 1.
> 1
> 
> and
> 
> $  /usr/local/perl4/bin/perl4.036  -wle 'exit 1 == 1'; echo $?
> 1
> $  /usr/local/perl4/bin/perl4.036  -wle 'exit 1 == 0'; echo $?
> 1
> $  /usr/local/perl4/bin/perl4.036  -wle 'exit(1 == 1)'; echo $?
> 1
> $  /usr/local/perl4/bin/perl4.036  -wle 'exit(1 == 0)'; echo $?
> 0
> 

Doesn't it have to do with prototypes? Note the difference between:

    $ perl -wE 'sub f {say $_ [0]} f 2 == 2'
    1
    $ perl -wE 'sub f ($) {say $_ [0]} f 2 == 2'
    Useless use of numeric eq (==) in void context at -e line 1.
    2
    $


However,

    $ perl -wE 'say prototype "CORE::exit"'
    ;$
    $ perl -wE 'sub f (;$) {say $_ [0]} f 2 == 2'
    1
    $


> I'm not sure what 'EXPR' should be replaced with, in the documentation.

I don't have much a problem with the current documentation. For me, it's
clear if someone writes:

    EXPR1 * EXPR2

that if I were to replace 'EXPR1' with '1 + 2', and 'EXPR2' with '3 + 4',
the result won't be 21.

I guess one could do a s/\bEXPR\b/(EXPR)/g over perlfunc. I don't favour it;
IMO, it's already kind of implied.



Abigail

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