After a long time away from perl I have found myself in a new job where I need to use it again (to manipulate lots of xml files). Hello again!
My problem: After some data extraction with XML::LibXML I am getting long strings of text returned, like this:
4541 PT1M27S 4542 PT1M51S 4543 PT2M16S 4544 PT1M47S 4545 PT0M39S 4546 PT0M50S 4547 PT0M43S 4548 PT1M2S 4549 PT0M41S 4550 PT2M44S 4551 PT2M4S 4552 PT1M5S
4553 PT1M30S 4554 PT1M21S 4555 PT2M10S 4556 PT0M23S 4557 PT1M24S 4558 PT0M35S 4559 PT1M30S 4617 PT0M58S 4561 PT2M27S PT1M0S 4562 PT1M24S 4563 PT2M9S 456
4 PT3M8S 4565 PT0M32S 4566 PT0M50S 4567 PT1M30S 4568 PT0M57S 4569 PT1M7S 4570 PT0M55S 4571 PT1M1S 6592 PT0M18S 4790 PT0M20S 4791 PT0M18S 9254 PT1M45S 479
4 PT0M14S 4795 PT0M19S 4796 PT0M18S 6185 PT0M28S 6186 PT1M20S 6187 PT1M48S 6188 PT0M52S
(that's one line).
This actually represents pairs of values like this:
4541 PT1M27S
4542 PT1M51S
4543 PT2M16S
4544 PT1M47S
4545 PT0M39S
4546 PT0M50S
4547 PT0M43S
4548 PT1M2S
4549 PT0M41S
4550 PT2M44S
4551 PT2M4S etc
and I need to split the line(s) up into such pairs and put them into a hash. I can't figure out how to do this. Can anyone point me in the right direction?
my %hash = split /[\s+]/, $lineofdata;
does not work. It gives me this:
$VAR1 = {
'PT0M28S' => '',
'PT0M50S' => '',
'4545' => 'PT0M39S',
'PT0M32S' => '',
'PT1M7S' => '',
'4564' => 'PT3M8S',
'4557' => 'PT1M24S',
'PT0M19S' => '',
'PT2M9S' => '',
'4566' => 'PT0M50S',
'PT0M58S' => '',
'4543' => 'PT2M16S',
'PT0M20S' => '',
'PT2M44S' => '',
'4541' => 'PT1M27S',
'4561' => 'PT2M27S',
'PT1M47S' => '',
'4549' => 'PT0M41S',
'PT1M45S' => '',
'4568' => 'PT0M57S',
'4794' => 'PT0M14S',
'PT1M21S' => '',
'4551' => 'PT2M4S',
'6188' => 'PT0M52S',
'PT1M2S' => '',
'4796' => 'PT0M18S',
'4553' => 'PT1M30S',
'PT1M48S' => '',
'4570' => 'PT0M55S',
'' => '6187',
'4559' => 'PT1M30S',
'PT1M51S' => '',
'PT1M1S' => '',
'6186' => 'PT1M20S',
'4555' => 'PT2M10S',
'4562' => 'PT1M24S',
'PT1M5S' => '',
'PT0M23S' => '',
'PT0M35S' => '',
'4547' => 'PT0M43S',
'6592' => 'PT0M18S',
'PT1M30S' => '',
'4791' => 'PT0M18S'
};
Any pointers will be appreciated, thanks, Tony
My problem: After some data extraction with XML::LibXML I am getting long strings of text returned, like this:
4541 PT1M27S 4542 PT1M51S 4543 PT2M16S 4544 PT1M47S 4545 PT0M39S 4546 PT0M50S 4547 PT0M43S 4548 PT1M2S 4549 PT0M41S 4550 PT2M44S 4551 PT2M4S 4552 PT1M5S
4553 PT1M30S 4554 PT1M21S 4555 PT2M10S 4556 PT0M23S 4557 PT1M24S 4558 PT0M35S 4559 PT1M30S 4617 PT0M58S 4561 PT2M27S PT1M0S 4562 PT1M24S 4563 PT2M9S 456
4 PT3M8S 4565 PT0M32S 4566 PT0M50S 4567 PT1M30S 4568 PT0M57S 4569 PT1M7S 4570 PT0M55S 4571 PT1M1S 6592 PT0M18S 4790 PT0M20S 4791 PT0M18S 9254 PT1M45S 479
4 PT0M14S 4795 PT0M19S 4796 PT0M18S 6185 PT0M28S 6186 PT1M20S 6187 PT1M48S 6188 PT0M52S
(that's one line).
This actually represents pairs of values like this:
4541 PT1M27S
4542 PT1M51S
4543 PT2M16S
4544 PT1M47S
4545 PT0M39S
4546 PT0M50S
4547 PT0M43S
4548 PT1M2S
4549 PT0M41S
4550 PT2M44S
4551 PT2M4S etc
and I need to split the line(s) up into such pairs and put them into a hash. I can't figure out how to do this. Can anyone point me in the right direction?
my %hash = split /[\s+]/, $lineofdata;
does not work. It gives me this:
$VAR1 = {
'PT0M28S' => '',
'PT0M50S' => '',
'4545' => 'PT0M39S',
'PT0M32S' => '',
'PT1M7S' => '',
'4564' => 'PT3M8S',
'4557' => 'PT1M24S',
'PT0M19S' => '',
'PT2M9S' => '',
'4566' => 'PT0M50S',
'PT0M58S' => '',
'4543' => 'PT2M16S',
'PT0M20S' => '',
'PT2M44S' => '',
'4541' => 'PT1M27S',
'4561' => 'PT2M27S',
'PT1M47S' => '',
'4549' => 'PT0M41S',
'PT1M45S' => '',
'4568' => 'PT0M57S',
'4794' => 'PT0M14S',
'PT1M21S' => '',
'4551' => 'PT2M4S',
'6188' => 'PT0M52S',
'PT1M2S' => '',
'4796' => 'PT0M18S',
'4553' => 'PT1M30S',
'PT1M48S' => '',
'4570' => 'PT0M55S',
'' => '6187',
'4559' => 'PT1M30S',
'PT1M51S' => '',
'PT1M1S' => '',
'6186' => 'PT1M20S',
'4555' => 'PT2M10S',
'4562' => 'PT1M24S',
'PT1M5S' => '',
'PT0M23S' => '',
'PT0M35S' => '',
'4547' => 'PT0M43S',
'6592' => 'PT0M18S',
'PT1M30S' => '',
'4791' => 'PT0M18S'
};
Any pointers will be appreciated, thanks, Tony