in reply to Re: Help w/ regex in filename
in thread Help w/ regex in filename
Ok heres what I updated it to.
#!/usr/bin/perl use DBI; use File::Tail; use POSIX(); our $bWin; BEGIN { $bWin = ($^O eq "MSWin32") ? 1 : 0; } Loop(); sub Loop { print "Updating Server Log -> DB\n"; Update_DB_Actions(); } sub Update_DB_Actions { my $dbh = DBI->connect('DBI:mysql:database=arma3;host=localhost',' +root','root') || die "Could not connect to database: $DBI::errstr"; my $filename = POSIX::strftime('ServerLog(%m-%d-%Y).log', localtim +e ); my $log = "D:\\ServerTools\\Logs\\$filename"; my $qu_re1 = q{(.?) started server @ (\d+):(\d+):(\d+)}; my $qu_re2 = q{(.?) restarted server @ (\d+):(\d+):(\d+)}; my $qu_re3 = q{(.?) stopped server @ (\d+):(\d+):(\d+)}; my $file = File::Tail->new(name=>$log); while(defined($line=$log->read)) { my $sql = "INSERT INTO `actions` (log) VALUES (?)"; $insa = $dbh->prepare($sql) or die $!; if($line =~ /$qu_re1/i || /$qu_re2/i || /$qu_re3/i) { $insa->execute($line); print "Inserted Action!\n"; } } unlink $log; }
But now I get a new error.
Can't locate object method "read" via package "D:\ServerTools\Logs\Ser +verLog(07- 06-2013).log" (perhaps you forgot to load "D:\ServerTools\Logs\ServerL +og(07-06-2 013).log"?) at script.pl line 112.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Help w/ regex in filename
by davido (Cardinal) on Jul 06, 2013 at 04:14 UTC | |
|
Re^3: Help w/ regex in filename (varnames)
by Anonymous Monk on Jul 06, 2013 at 07:35 UTC |