Assistance with printing complex data structure
Assistance with printing complex data structure
(OP)
Given this data structure, can anyone help me print it out in the format shown below?
The required output format is shown below. The column titles are shown simply for clarity, I don't need these printing.
CODE
$VAR1 = { 'DepartureTime' => '05:53:00', 'PrivateCode' => '4483928', 'VehicleJourneyTimingLinkRef' => { '7' => 'PT1M16S', '6' => 'PT1M34S', '4' => 'PT2M33S', '5' => 'PT0M37S' } }; $VAR2 = { 'PrivateCode' => '4483929', 'DepartureTime' => '06:10:00', 'VehicleJourneyTimingLinkRef' => { '5' => 'PT0M37S', '21' => 'PT1M34S', '7' => 'PT1M16S', '6' => 'PT1M35S', '19' => 'PT0M43S', '4' => 'PT2M32S', '20' => 'PT2M19S', '16' => 'PT1M43S', '15' => 'PT0M55S', '18' => 'PT1M32S', '22' => 'PT1M36S', '23' => 'PT1M10S', '24' => 'PT0M40S', '17' => 'PT0M48S' } };
CODE
VJTL Private Ref Time Departure Code 4 PT2M33S 05:53:00 4483928 5 PT0M37S 05:53:00 4483928 6 PT1M34S 05:53:00 4483928 7 PT1M16S 05:53:00 4483928 5 PT0M37 06:10:00 4483929 6 PT1M35S 06:10:00 4483929 7 PT1M16S 06:10:00 4483929 15 PT0M55S 06:10:00 4483929 16 PT1M43S 06:10:00 4483929 etc
RE: Assistance with printing complex data structure
As I understand, those $VAR1 and $VAR2 are separate variables, so I would use a sub like this :
CODE --> Perl
Feherke.
feherke.github.io
RE: Assistance with printing complex data structure
RE: Assistance with printing complex data structure
CODE
Currently, I am adding them as a hash as follows:
CODE
Would you concur that using an array would be the best option? If so, can you help with the syntax? I've tried various options but the best I've managed to come up with added all the values as a single dimensional array (a long list) rather than keeping the pair values together.
RE: Assistance with printing complex data structure
RE: Assistance with printing complex data structure
That make a world of difference. Then just the %{ .. } dereferencing has to be avoided and no need to play with manually set order :
CODE --> Perl
Feherke.
feherke.github.io
RE: Assistance with printing complex data structure
Can't call method "Keys" on unblessed reference at myscript.pl line 118.
RE: Assistance with printing complex data structure
Interesting. This is my test script :
CODE --> Perl
Feherke.
feherke.github.io
RE: Assistance with printing complex data structure
CODE
RE: Assistance with printing complex data structure
CODE
RE: Assistance with printing complex data structure
Great. That Tie::IxHash caught me. When added the items one by one, wasn't able to get them back in order.
CODE --> Perl
Feherke.
feherke.github.io
RE: Assistance with printing complex data structure