perl script to read file and write data to other log files with regx

#!/usr/bin/perl

use strict;
use warnings;
use Data::Dumper;
my %hash;

while (my $line = <DATA> ) {
chomp($line);
$line =~ m/^(\d+_\d+_\d+);/;
$hash{$1} .= "$line\n";

}

for my $outfile (keys %hash ){
if ( -e "$outfile.log" ){
next ;
}
open (WRT,">$outfile.log") or die "cannot open file : $!";
print WRT "$hash{$outfile}";
close ( WRT ) ;
}


__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
~

perl tutorial with exercises -- 1

http://www.sthomas.net/roberts-perl-tutorial.htm

perl tutorial with exercises --

http://vsbabu.org/tutorials/perl/index.html#toc2


Other Articles

Enter your email address: