"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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |