D
DanielC
INPUT (tt):
INFO - {
'Result' => 'failure',
'Id' => '1564',
'dataRecv' => 'adfasdfi',
'dataSent' => 'rqerqerer',
'elapsedTime' => '7.023359',
'externalId' => 'AI2JL4PBLG',
'responseCode' => '0',
'responseMsg' => 'n/a',
'sentAt' => '2011-04-27 00:08:02',
'serviceId' => '13',
'serviceName' => 'abc',
'timeInQueue' => 1
}
INFO - {
'Result' => 'failure',
'Id' => '1565',
'dataRecv' => 'asdfghjkl',
'dataSent' => 'qwerrtyu',
'elapsedTime' => '1.106637',
'externalId' => 'AI2JL4X1EN',
'responseCode' => '410',
'responseMsg' => 'Customer account not active',
'sentAt' => '2011-04-27 00:14:02',
'serviceId' => '13',
'serviceName' => 'def',
'timeInQueue' => 1
}
SCRIPT (test.pl):
#!/usr/bin/perl -w
#
my %hash;
local $/ = "\n\n";
while (my $line = <>)
{
$line =~ s/INFO - {/(/;
$line =~ s/}/)/;
%hash = $line;
print "$hash{'sentAt'}\n";
}
I know how to read the input line by line, then put them into a hash.
Here I just want to try read one section of data into a hash. However
it failed with below errors. Can someone shed some light on this
script and make it work?
$ cat tt|perl test.pl
Odd number of elements in hash assignment at test.pl line 10, <> chunk
1.
Use of uninitialized value in print at test.pl line 11, <> chunk 1.
Odd number of elements in hash assignment at test.pl line 10, <> chunk
2.
Use of uninitialized value in print at test.pl line 11, <> chunk 2.
INFO - {
'Result' => 'failure',
'Id' => '1564',
'dataRecv' => 'adfasdfi',
'dataSent' => 'rqerqerer',
'elapsedTime' => '7.023359',
'externalId' => 'AI2JL4PBLG',
'responseCode' => '0',
'responseMsg' => 'n/a',
'sentAt' => '2011-04-27 00:08:02',
'serviceId' => '13',
'serviceName' => 'abc',
'timeInQueue' => 1
}
INFO - {
'Result' => 'failure',
'Id' => '1565',
'dataRecv' => 'asdfghjkl',
'dataSent' => 'qwerrtyu',
'elapsedTime' => '1.106637',
'externalId' => 'AI2JL4X1EN',
'responseCode' => '410',
'responseMsg' => 'Customer account not active',
'sentAt' => '2011-04-27 00:14:02',
'serviceId' => '13',
'serviceName' => 'def',
'timeInQueue' => 1
}
SCRIPT (test.pl):
#!/usr/bin/perl -w
#
my %hash;
local $/ = "\n\n";
while (my $line = <>)
{
$line =~ s/INFO - {/(/;
$line =~ s/}/)/;
%hash = $line;
print "$hash{'sentAt'}\n";
}
I know how to read the input line by line, then put them into a hash.
Here I just want to try read one section of data into a hash. However
it failed with below errors. Can someone shed some light on this
script and make it work?
$ cat tt|perl test.pl
Odd number of elements in hash assignment at test.pl line 10, <> chunk
1.
Use of uninitialized value in print at test.pl line 11, <> chunk 1.
Odd number of elements in hash assignment at test.pl line 10, <> chunk
2.
Use of uninitialized value in print at test.pl line 11, <> chunk 2.