"I did not realize that you could just stick {} pretty much anywhere you want."

That's called a "block", and they can't quite go anywhere, but pretty close.

Blocks are how we limit the "scope" of something. Anything defined within that block is limited to that scope. This is where my and local for example come in to play. Here's a couple of examples:

use warnings; use strict; my $thing = 123; { my $thing = 456; } print $thing; # 123 open my $fh, '<', 'file.txt' or die $!; { local $/; # slurp in a file my $contents = <$fh> ... } # now we go back to reading a file line-by-line again while (<$fh>){ ... }

Subroutines (functions/methods) are blocks as well, and some functions even take blocks as parameters (or operate in "block mode" so it appears to take a block as a param):

my @list = map {$_ => 1} @other_list; my @filtered_list = grep {$_ =~ /blah/} @some_list;

...etc.

Please see AnomalousMonk's post here for how my above example is actually quite broken if taken literally. Haste took rank, but we have people who correct hasty things thankfully. I should have added an "untested" warning or better.


In reply to Re^3: restrict use of regex module in script by stevieb
in thread restrict use of regex module in script by pmpmmpmp

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.