利用perl decode json

2010-08-10

记录下perl 怎么decode json

#!/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