I have data from JSON using Data::Dumper that looks like the following when I -
print Dumper $json_response;
$VAR1 = {
'report' => [
{
'stat' => 1,
'timestamp' => '1360775722',
'status' => '"Active"',
'name' => '"09:15 am, 13 Feb, 2013"',
'id' => '200'
},
{
'stat' => 1,
'timestamp' => '1360775806',
'status' => '"Active"',
'name => '"09:16 am, 13 Feb, 2013"',
'id' => '199'
}
],
'username' => 'test'
};
Is this type of data a hash with anonymous array? I am able to grab each key, value doing:
foreach ( @{$json_response->{report}} ){
my %report;
$report{status} = $_->{status};
$report{id} = $_->{id};
print "CGGSID: $report{id}\n";
print "Status: $report{status}\n\n";
}
How would I sort the data by the 'id'? I know I can push the 'id' to an array and probably sort the array, but trying to see other, more efficient way for sorting this. Thank you!
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.