Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: "open" Best Practices

by stevieb (Canon)
on Jul 11, 2019 at 14:53 UTC ( #11102687=note: print w/replies, xml ) Need Help??

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; }

Replies are listed 'Best First'.
Re^2: "open" Best Practices
by haukex (Bishop) on Jul 11, 2019 at 15:02 UTC

    Thanks, and yes, good points! The node is aimed at people using the open statement in a "non-best-practice" way, so I'd like to keep the node short enough so that they might still read it (hence all the bold text and TL;DR at the top), and I'd like to keep the focus on the open statement itself - I left out a discussion e.g. of piped opens and checking close for errors and such intentionally, because when answering questions about that, I have other nodes I'd link to instead. Perhaps your reply to my node pointing these things out is enough? :-)

    Update: Ok, I've updated the root node!

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11102687]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2021-01-18 19:50 GMT
Find Nodes?
    Voting Booth?