CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate: Re: [zapzap] Format Data: Edit Log



FishMonger
Veteran / Moderator

Oct 25, 2013, 6:49 AM


Views: 4602
Re: [zapzap] Format Data


Code
#!/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

Quote
['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)


Edit Log:
Post edited by FishMonger (Veteran) on Oct 25, 2013, 6:49 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives