Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Check Re^8: Unhappy returns (just updated) for some tests as to what gets returned when. Apparently:

  • If the last thing that happened was an iteration of a for loop, you will get back !1, alias scalar false (it is 0 and an empty string at the same time).
  • If the last thing that happened was an iteration of a while loop, you get back nothing at all.
  • If the last thing that happened was an if block, you get back the value of the last expression evaluated – that would be either the condition, if it evaluated to false, or the last expression from the body of the conditional block.

In other words, what perlsub says is deceptive and incomplete.

Update: oh goodness, it gets weirder still:

  • If the last thing that happened was an iteration of the do {} while $cond or do {} until $cond pseudo-loop, you get back a code reference (whether the condition turned out true of false).

It’s probably safe to say that Perl simply has no rule here, and that what you get back from a sub depends on implementation details of perl.

Makeshifts last the longest.


In reply to Re: "last expression" quiz by Aristotle
in thread "last expression" quiz by fxn

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2024-04-18 02:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found