
FishMonger
Veteran
/ Moderator
Oct 25, 2013, 6:49 AM
Post #5 of 7
(5034 views)
|
#!/usr/bin/perl use strict; use warnings; chomp(my @lines = (<DATA>)[0..4,-4..-1]); my %HoA; foreach my $line (@lines) { my ($key, $value) = split /\s+/, $line; push @{ $HoA{$key} }, $value; } foreach my $key (sort keys %HoA) { printf "['%s',%s]\n", $key, join(',', @{$HoA{$key}}); } __DATA__ 23:00 37 22:45 26 22:30 14 22:15 15 22:00 43 ... more of the same ... ... more of the same ... ... more of the same ... 23:00 33 22:45 22 22:30 11 22:15 12 22:00 21 Output from C:\test>zapzap.pl
['22:00',43,21] ['22:15',15,12] ['22:30',14,11] ['22:45',26,22] ['23:00',37]
(This post was edited by FishMonger on Oct 25, 2013, 6:49 AM)
|