Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

1)Naked Blocks can be used to turn off warnings for the scope of the block - useful if you're doing some work that will encounter a lot of "uninitialized variable" warnings.

Blocks are used to create scope. What you do with that scope is up to you.

This kind of scope is 'lexical'. You can do a lot with it:

  • Use a lexical pragma (like strict, warnings or utf8)
  • Use a lexical variable (declared with my)
  • Declare a global variable lexically (with our)
  • Temporarily give a package global another value (using local)
Each of these use the lexical scope the block creates.

You don't create a block to turn off warnings. You use no warnings to turn them off. The block only limits the effect of that statement. It's important to know that the block itself has nothing to do with warnings (well, you can get warnings regarding the block of course).

This lexical stuff goes for all code blocks, bare or belonging to something like if or while.

Bare blocks (in this thread called 'naked blocks'; haven't seen them called that anywhere else) act like loops. In the code blocks for while, until and for, you can the use loop controlling operators next, redo and last. These can also be used with bare blocks: redo goes to the beginning of the block, last goes to the end.

You cannot use loop control operators with non-loop constructs like do, if and eval.

if (...) { ...; last if ...; # cannot use C<last> with G<if> ...; }
You can put a bare block in if's block to create the loop you want:
if (...) { { ...; last if ...; # can use C<last> with a bare block ...; } }
Bare blocks are used like this everywhere, but often disguised: double curlies are used to make the code look nicer.
if (...) {{ ...; last if ...; # same ...; }}
So if you see doubled curly brackets, the extra block is probably only there to make breaking out of it easy.

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.

In reply to Re: Re: A few random questions from Learning Perl 3 by Juerd
in thread A few random questions from Learning Perl 3 by sulfericacid

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, 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, 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.
  • Log In?

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

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (4)
    As of 2020-02-29 04:25 GMT
    Find Nodes?
      Voting Booth?
      What numbers are you going to focus on primarily in 2020?

      Results (128 votes). Check out past polls.