Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: "open" Best Practices

by stevieb (Canon)
on Jul 11, 2019 at 14:53 UTC ( [id://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 (Archbishop) 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?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 12:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found