Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

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

I've always thought of this property of p5 if/elsif/else blocks as the blocks 'leaving behind their last value', analogous to the block of a do or sub. Whether that is a strictly accurate description of what happens internally doesn't really matter, it's just an aid memoire to my remembering the behaviour.

I've often wished that it was property of all blocks. It could, for example, provide a solution to the problem LanX describes in global regex returning a list of arrays?. That of obtaining a (full) list of matches from a global regex.

Something like (the non-working):

my @filtered = grep{ ... } do{ [ $1, $2 ] while $s =~ m[(.)(.)]g };

I've also been frustrated that I can't obtain this list directly without going through an intermediary push to an array. Presumably P6 has an answer to this already?

I guess that a different (better) approach in P5 syntax would be another modifier on the regex (perhaps /gg).


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^5: in search of a more elegant if then else by BrowserUk
in thread in search of a more elegant if then else 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":



  • 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 studying the Monastery: (5)
As of 2024-03-29 00:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found