All,
Background: What got me thinking
As has been discussed recently:
my $persist if 0; # illegal >= 5.10.0
Is an unusual construct which effectively creates a
state variable due to the weird way perl handles lexicals (compile and runtime). It has been argued, that
my should never be used with a postfix conditional. That is probably a good idea even when you only want a lexical to be created if some other condition is true. An if block should be used for that.
Actual Question: (see this also)
My question has to do with the following unrelated construct:
if (my $result = some_func()) {
# do something with $result
}
There are a couple of reasons you might want to do this:
- You want $result scoped as small as possible
- The some_func() is impure and subsequent calls will change the results
This leaves a few questions for me.
- Is there any sane alternative that satisfies the two reasons above?
- Is the implicit scoping of $result to the if block going to continue to work in Perl 6
To be honest, I really don't care as I can count the number of times I have used that construct on one hand. I ask because the recent state discussions have made me wonder if Perl 6 is going to clean up all the cobwebs in the corners.
Questions Answered
Update: Feel free to continue to contribute if you have something to add, but my questions have been answered - see here, here, and here
Update: Added a couple of headings
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.