The scoping rules are much simpler now. And because blocks are closures, you can pass parameters to them, which are scoped to the block. So you could write your statement like this:
if /^ (f+) / -> *$i { # Do stuff }
where the * on the parameter list treats the pattern match result as binding to a list value, so the search result acts like a list value and binds $1 to $i. And arguably it's more readable because it puts the first thing that happens, the pattern match, out front. The parameter binding only happens if the pattern match succeeds.

Or look at it another way. Suppose you run into a new control construct:

frob my $x = bar() {...}
Tell me quick whether $x is local to that block? In the Perl 5 world, you don't know for sure, because the scoping rules are arbitrary, and change between builtins and user-defined control verbs. In the Perl 6 world you know it isn't local, because the my isn't inside the block. Period. On the other hand, if you see
frob bar() -> $x {...}
then you absolutely know that $x is local because it's explicitly being passed as a parameter.

I think people who initially perceive this as Bad or Ugly will eventually come around to seeing it as Kinda Pretty.


In reply to Re^6: Perl oddities ("if" w/o parens) by TimToady
in thread Perl oddities by brian_d_foy

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!
  • 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:
    & &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.