in reply to Re^2: converting JSON to CSV
in thread converting JSON to CSV

Just TIMTOWTDI...

AnomalousMonk already mentioned the issue with local. Localizing is pointless when it happens at top level - in the same way as my variables are global variables if declared at top level in a program that consists in just 1 file without imports.

So, local needs a place. A bare block is convenient:

my $text; # but see above ;-) { local( $/, *FH ) ; open( FH, '<', 'aws.json' ); $text = <FH>; } # $/ restored to default here # FH is an empty typeglob in the symbol table

See also my/local, space/time (was: Re: The difference between my and local)

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^4: converting JSON to CSV
by haukex (Archbishop) on Apr 08, 2017 at 09:14 UTC

    Just to pick a nit:

    Localizing is pointless when it happens at top level

    Not entirely, e.g. if you've got a file foo.pl that does local $/, and a file bar.pl that does do "foo.pl" (any of eval/do/require/use), then bar.pl is protected from the change to $/.

    I know you also said "a program that consists in just 1 file", but I'd say foo.pl doesn't know if it's being run by perl foo.pl or by being done from another script, or perhaps being run in a persistent process. So localizing would be playing it safe.