... 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: <%-{-{-{-<