Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

You're right; I intended to link to perlsub. I still think that it's applicable, though I would be in full agreement that the documentation ought to be more explicit about it, unless specifying the behavior more explicitly locks future p5p development into a behavior that they would prefer to change.

Update:

I've submitted the following perlbug:
----------------------------------------------------------------- [Please describe your issue here] perlsub says this about implicit returns: If no return is found and if the last statement is an expression, its value is returned. If the last statement is a loop control structure like a foreach or a while , the returned value is unspecified. Now consider the following code: $x = 1; sub foo { if( $x ) { 0 } } print foo(), "\n"; The output will be 0, presumably because the last statement is the expression, numeric '0'. How about this: $x = 0; sub foo { if( $x ) { 1 } } print foo(), "\n"; The output will be 0, presumably because the last expression to be evaluated is '$x', which has a value of 0. But the last statement to execute is literally "if()". If we run this past B::Concise we find that the construct is converted into something similar to sub { $x and 1 }, so it is intuitive that the return value will be $x if false, or 1 if $x is true. Although this behavior is possibly a little confusing to someone who doesn't read between the lines in perlsub, it seems reasonably stable (it's been with us forever), and unlikely to change in the future. Therefore, perlsub should state the following: If no L<return> is found and if the last statement is an expression, its value is returned. If the last statement is an C<if( CONDITION ) { BLOCK }> construct, the value of the return value will come from C<BLOCK> if C<CONDITION> is true, or from C<CONDITION> if C<CONDITION> is false. Relying on this behavior is detrimental to code legibility. If the last statement is a loop control structure like a C<foreach> or a C<while>, the returned value is unspecified. [Please do not change anything below this line] ----------------------------------------------------------------- ---

If it gains the consideration of p5p I anticipate they will want to rehash the wording a bit before proceeding, or possibly simply make the if(){} construct explicitly unspecified, as has been done with loop constructs.


Dave


In reply to Re^3: return value of "if" (documentation?) by davido
in thread return value of "if" (documentation?) by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (11)
    As of 2014-12-26 15:04 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (171 votes), past polls