... let me know if its good coding.
What follows is in part my own personal preference, but a lot is current idiomatic Perl; I won't rigorously distingush between the two. My comments pertain to your
local( $/, *FH ) ;
open( FH, '<', 'aws.json' );
my $text = <FH>;
section of code; the rest is from the
AnonyMonk's
post and looks good to me.
Caveat: I haven't actually
tested any of the code on which I'm commenting.
-
local( ..., *FH ) ;
open( FH, '<', 'aws.json' );
local-izing package global variables is better than nothing and you're already using the three-argument open, but it's even better to use a lexical filehandle and check the success of the file open:
my $filename = 'aws.json';
open my $fh, '<', $filename or die "opening '$filename': $!";
(You could also turn on autodie globally with a use autodie; statement, but I prefer the flexibility of individual die clauses.)
-
local( $/, ... ) ;
...
my $text = <FH>;
To do this idiomatic file "slurp" read, $/ must be undefined. Again, globally undefining this variable (and that's effectively what you're doing, even using local) is not preferred: local-ize in the narrowest practicable scope:
my $text = do { local $/; <$fh>; };
-
With the previous two changes, the
local( $/, *FH ) ;
statement (and its possibly problematic global effects) goes away entirely. (Update: Actually, the local( ..., *FH ) ; statement effectively has no semantic global effect WRT the *main::FH glob because it is local-izing the glob at the top level of the script, where all globs come into existence anyway. The only practical "global" effect is on your expectations: you may be lulled into thinking that you have invoked some kind of magical protection for yourself when you have not.)
Give a man a fish: <%-{-{-{-<
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.