Something like this?

our ($For, $While, $Map, $Grep, $If) = qw( For While Map Grep If) ; local $For = 'local' for 1; local $While = 'local' while ! $a++; map +(local $Map = 'local'), 1; grep +(local $Grep = 'local'), 1; local $If = 'local' if 1; print "For: $For\n"; print "While: $While\n"; print "Map: $Map\n"; print "Grep: $Grep\n"; print "If: $If\n"; __END__ For: For While: While Map: Map Grep: Grep If: local
Here, all loop constructs introduces a scope for the expression just as they would if it was a block. if however doesn't.

While speaking about blocks for map and grep (and sort):

map { use strict; } LIST
fails with '"use" not allowed in expression ...'. A do block can be used to "upgrade" the block though avoid the ambiguity (see ysth's reply:
map do { use strict; }, LIST
works. (Interestingly, this uses map EXPR, LIST ...)

lodin


In reply to Re: statement vs. block? by lodin
in thread statement vs. block? by BrowserUk

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.