So, the perl JSON module is actually very easy and nice to use, it will convert your perl data structure into JSON without a sweat.
Here's a quick example which I hope will be useful :
#!/usr/bin/perl
use strict;
use warnings;
use JSON;
my %hash;
foreach my $file (@list_of_files) {
open(FILE,"$file");
my @list;
while (<FILE>) {
push(@array,$_);
}
%hash{$file} = [@array]; # store array reference in hash
}
my $obj = \%results;
my $json = new JSON;
my $js = $json->encode($obj, {pretty => 1, indent => 2}); # convert Perl data structure to JSON representation
$output .= "$js\n\n";
print $output;
And done!
Ok, obviously there's a instead of () in the while loop, but Blogger keeps interpreting it as HTML :-)
ReplyDeleteOK, once again FILE in between angled brackets
ReplyDelete