Last year feherke kindly helped me resolve a problem with printing a complex data structure. I have found the resultant script enormously helpful since then. An influx of work since the corona lockdown has left me with a need to slightly modify the print routine. I have received a number of data files in which the data is not sorted by time of departure and it would greatly help readability to print out the data in departure time order.
The data structure is:
The print routine is:
The sorting done above is still vital and needs to be done. However, if the data file contains data which is not in order by departure time it prints them out in the same unsorted departure time order. I would like to print them out from the earliest to the last departure.
Can anyone assist in changing the above routine?
The data structure is:
Code:
$VAR1 = {
'DepartureTime' => '05:53:00',
'PrivateCode' => '4483928',
'VehicleJourneyTimingLinkRefOrder' => [
[
'4',
'PT2M33S'
],
[
'5',
'PT0M37S'
],
[
'6',
'PT1M34S'
],
[
'7',
'PT1M16S'
]
]
};
The print routine is:
Code:
sub print_as_table {
my $data = shift;
foreach my $item (@{$data->{VehicleJourneyTimingLinkRefOrder}}) {
print $item->[0], ' ', $item->[1], ' ', $data->{DepartureTime}, ' ', $data->{PrivateCode}, "\n";
}
}
The sorting done above is still vital and needs to be done. However, if the data file contains data which is not in order by departure time it prints them out in the same unsorted departure time order. I would like to print them out from the earliest to the last departure.
Can anyone assist in changing the above routine?