use strict; use warnings; my %log; while(<DATA>){ chomp; my ($key, $value) = split /;/, $_; push @{$log{$key}}, $value; }
foreach my $k (keys %log){ open my $k_fh, '>', "$k.log" or die "Could not open the file - $k.log : $! \n"; foreach my $v (@{$log{$k}}) { print $k_fh $k.';'.$v."\n" or die "Could not print to the file - $k.log : $! \n"; } } __DATA__ 3_21_2010;11:12\\trafic info 3_21_2010;11:34\\trafic info 3_21_2010;13:21\\trafic info 3_22_2010;11:12\\trafic info 3_22_2010;11:34\\trafic info 3_22_2010;13:21\\trafic info 3_22_2010;11:12\\trafic info 3_23_2010;11:34\\trafic info 3_23_2010;13:21\\trafic info 3_23_2010;13:21\\trafic info 3_24_2010;11:12\\trafic info 3_24_2010;11:34\\trafic info 3_24_2010;13:21\\trafic info Cheers, Parag On Thu, Oct 14, 2010 at 7:54 AM, yo RO <lyn...@gmail.com> wrote: > Hello I need to split a log file per days > I have a file in txt format and I want to create a file with all data > from one day in one file > I will give example > > I have this imput > 3_21_2010;11:12\\trafic info > 3_21_2010;11:34\\trafic info > 3_21_2010;13:21\\trafic info > 3_22_2010;11:12\\trafic info > 3_22_2010;11:34\\trafic info > 3_22_2010;13:21\\trafic info > 3_22_2010;11:12\\trafic info > 3_23_2010;11:34\\trafic info > 3_23_2010;13:21\\trafic info > 3_23_2010;13:21\\trafic info > 3_24_2010;11:12\\trafic info > 3_24_2010;11:34\\trafic info > 3_24_2010;13:21\\trafic info > > I want to have in output 3 file > file 1: name 3_21_2010.log > contain > 3_21_2010;11:12\\trafic info > 3_21_2010;11:34\\trafic info > 3_21_2010;13:21\\trafic info > > file 2 : 3_22_2010.log > contain > > 3_22_2010;11:12\\trafic info > 3_22_2010;11:34\\trafic info > 3_22_2010;13:21\\trafic info > 3_22_2010;11:12\\trafic info > > and like this > please help help me with this > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >