2007/9/3, sivasakthi <[EMAIL PROTECTED]>: > Hi All, > > I have tested the following script for reading the log files and write > in to the file, > > > #!/usr/bin/perl > use strict; > use warnings; > use File::Tail; > my $file=File::Tail->new("/log/path"); > while (defined(my $line=$file->read)) > { > my ($time,$lport,$ip,$stats,$rport)=split" ",$line; > &writedata; > sub writedata > { > open FF,">>/tmp/test || die "can't create file /tmp/test $!"; > printf FF "$time,$lport,$ip,$stats,$rport"; > close FF; > } > >
wrong things are: 1) you don't close a block; 2) don't pass arguments to subroutine; 3) open file wrong. It can be modified to, #!/usr/bin/perl use strict; use warnings; use File::Tail; my $file=File::Tail->new("/log/path"); while (defined(my $line=$file->read)) { my ($time,$lport,$ip,$stats,$rport)=split/\s+/,$line; writedata($time,$lport,$ip,$stats,$rport); } sub writedata { my ($time,$lport,$ip,$stats,$rport) = @_; open FF,'>>/tmp/test' or die "can't create file /tmp/test $!"; print FF "$time,$lport,$ip,$stats,$rport"; close FF; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/