I have a Perl Data::Dumper file (data.txt) with two arrays that i need to convert into JSON.
Here's what looks like my data.txt:
$stats = {
'oldtime' => '04',
'parsedlines' => 8,
'day_lines' => [
undef,
8
],
'actions' => {
'microbe' => 1
},
'lastnick' => 'Sky',
'words' => {
'Sky' => 1,
'microbe' => 9
},
'times' => {
'04' => 8
},
'totallines' => 8,
'word_times' => {
'microbe' => [
9
],
'Sky' => [
1
]
},
'lastvisited' => {
'microbe' => 1,
'Parts:' => 1,
'Sky' => 1
},
'line_times' => {
'microbe' => [
3
],
'Sky' => [
1
]
},
'lengths' => {
'microbe' => 36,
'Sky' => 11
},
'lastnormal' => '[04:35:01] <Sky> ;algkagkaga
',
'day_times' => [
undef,
[
8,
0,
0,
0
]
],
'days' => 1,
'joins' => {
'microbe' => 1,
'Sky' => 1
},
'monocount' => 0,
'lines' => {
'Sky' => 1,
'microbe' => 3
}
};
$lines = {
'actionlines' => {
'microbe' => [
'[04:33:53] * microbe is doing just a test
'
]
},
'sayings' => {
'Sky' => [
';algkagkaga'
],
'microbe' => [
'Hello'
]
}
};
So as you can see, there is 2 arrays: $stats and $lines.
I want to convert them in JSON.
Someone on here (Borodin) came with a working solution, but it output only the second array ($lines). Here's his solution:
use strict;
use warnings qw/ all FATAL /;
use JSON;
print encode_json( do 'data.txt' or die $! ), "\n";
But here's what it output:
{
"actionlines":{
"microbe":[
"[04:33:53] * microbe is doing just a test\n"
]
},
"sayings":{
"microbe":[
"Hello"
],
"Sky":[
";algkagkaga"
]
}
}
So it output only $lines array... Any idea of what i can do to have it working ?