file manipulation

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 [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
http://learn.perl.org/
Muzammil [ Mo, 14 Februar 2011 11:46 ] [ ID #2055138 ]

Re: file manipulation

--90e6ba5bb8d90338a0049c407d77
Content-Type: text/plain; charset=ISO-8859-1

maybe this script may help:

use strict;
use warnings;

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

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

perl script.pl *.txt

On Mon, Feb 14, 2011 at 11:46, Muzammil <muzammil.cse [at] 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 [at] perl.org
> For additional commands, e-mail: beginners-help [at] 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

--90e6ba5bb8d90338a0049c407d77--
oleber [ Mo, 14 Februar 2011 17:24 ] [ ID #2055139 ]
Perl » gmane.comp.lang.perl.beginners » file manipulation

Vorheriges Thema: Unable to determine error source
Nächstes Thema: DBD::mysql::st execute failed