http://www.perlmonks.org?node_id=11102687


in reply to "open" Best Practices

Nice! I'd add a blurb about using close(), as well as a scoped block example (perhaps linking the two). One good example of when to use a block is using a local record separator variable (the close isn't really necessary in this case, but I digress):

my $file = 'test.txt'; my $json; { local $/; open my $fh, '<', $file or die $!; $json = <$fh>; close $fh; }