develooper Front page | perl.beginners | Postings from February 2011

Re: file manipulation

Thread Previous
From:
marcos rebelo
Date:
February 14, 2011 08:25
Subject:
Re: file manipulation
Message ID:
AANLkTik+Fj6Ppiki0W9z7G3wnQ2K7kDy9MLH=skCbVVq@mail.gmail.com
maybe this script may help:

use strict;
use warnings;

my %data;
while ( defined ( my $line = readline ) )  {
    chomp $line;
    my ($date, $num) = split(/,/, $line);
    push(@{$data{$date}}, $num);
}

foreach my $date (sort keys %data) {
    print join(',', $date, @{$data{$date}}), "\n";
}

perl script.pl *.txt

On Mon, Feb 14, 2011 at 11:46, Muzammil <muzammil.cse@gmail.com> wrote:

> file 1
> 2010-11-21,2
> 2010-12-01,1
>
> file 2
> 2010-11-22,12
> 2010-12-01,11
>
> this is for GD graph and the file file should be like this
> 2010-11-21,2
> 2010-11-22,12
> 2010-12-01,1,11
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> http://learn.perl.org/
>
>
>


-- 
Marcos Rebelo
http://www.oleber.com/
Milan Perl Mongers leader https://sites.google.com/site/milanperlmongers/
Webmaster of http://perl5notebook.oleber.com


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About