#/usr/bin/perl
# script 1
use Storable;
my %eTAG,$i;
$eTAG{'Truck'}{'Fuel'}="Gas"; $eTAG{'Truck'}{'mpg'}=15;
$eTAG{'SUV'}{'Fuel'}="Gas"; $eTAG{'SUV'}{'mpg'}=21;
#for illustration only
foreach $i (keys %eTAG){ print "$i\n"; }
store \%eTAG, 'fileHash.dat';
exit 0;
####
#!/usr/bin/perl
# Script #2
use Storable;
my $i, $href = retrieve('fileHash.dat',{binmode=>':raw'});
my %eTAG = %$href; #This was the key to getting it working.
foreach $i (keys %eTAG) { print "$i\n"; }
exit 0;
##
##
#/usr/bin/perl
# script 1 JSON version
use JSON;
my %eTAG,$i;
$eTAG{'Truck'}{'Fuel'}="Gas"; $eTAG{'Truck'}{'mpg'}=15;
$eTAG{'SUV'}{'Fuel'}="Gas"; $eTAG{'SUV'}{'mpg'}=21;
#for illustration only
foreach $i (keys %eTAG){ print "$i\n";}
my $JSONdata = encode_json(\%eTAG);
open(OFIL,">fileHash.dat"); print OFIL $JSONdata; close(OFIL);
exit 0;
##
##
#!/usr/bin/perl
# Script #2 JSON version
use JSON;
my $i, $href,$JSONdata;
open(IFIL,"; close(IFIL);
$href = decode_json($JSONdata);
my %eTAG = %$href; #This was the key to getting it working.
foreach $i (keys %eTAG) { print "$i $eTAG{$i}{'mpg'}\n"; }
exit 0;