in reply to Re^2: Beware of global! And bless the local!
in thread Beware of global! And bless the local!
"I should adopt anonymous blocks as a every-day programming technique"
Anonyblocks are just another tool in the toolset. I use them primarily in unit test files to separate out tests of a feature or method where I need to instantiate a new object for a test sequence.
For situations such as yours, I'd probably opt for a function instead of a block that's inline with the code. A subroutine provides the same scoping as the block does:
sub slurp_file { my ($fname) = @_; local $/; open my $fh, '<', $fname or die "Can't open damned '$fname' file: +$!"; my $data = <$fh>; close $fh or die $!; return $data; }
To each their own, there's more than one way to do it!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Beware of global! And bless the local!
by Your Mother (Archbishop) on Dec 12, 2019 at 17:10 UTC | |
by stevieb (Canon) on Dec 12, 2019 at 17:37 UTC | |
|
Re^4: Beware of global! And bless the local!
by Fletch (Bishop) on Dec 12, 2019 at 17:59 UTC |