利用perl decode json

记录下perl 怎么decode json

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/perl
use strict;
use warnings;
use JSON;

open my $fh, '<', './json.data';

my ($guid,$cip,$agent);
while ( my $line = <$fh> ) {
        my $result = index( $line, ':' );
        $line = substr( $line, $result + 1 );
        ($guid,$cip,$agent) = (decode_json($line)->{'guid'},decode_json($line)->{'cip'}, decode_json($line)->{'agent'});
        $^ = 'STDOUT_TOP';
        $~ = 'STDOUT';
        write;

}
close $fh;

format STDOUT_TOP =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"Page $%"
                                        SOJ_LOG_Report
GUID                                                                                IP
=================================================
.
format STDOUT =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<
$guid                                                                              $cip