I am currently trying to scan a log file on my server. I want to match my regex to my file name. This is the error I am getting.

Error opening D:\ServerTools\Logs\ServerLog\((\d+)-(\d+)-(\d+)@(\d+)-( +\d+)\.log ): Invalid argument at script.pl line 109

Here is my actual script

#!/usr/bin/perl -w use DBI; use File::Tail; 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 = q{ServerLog\((\d+)-(\d+)-(\d+)@(\d+)-(\d+)\.log +)}; # my ($sec,$min,$hour,$day,$month,$year) = (localtime)[0,1,2,3,4,5 +]; # my $filename = sprintf("ServerLog(%02d-%02d-%04d).log",$month+1, +$day,$year+1900); 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+)}; $file = File::Tail->new($log); while (defined($line=$file->read)) { my $sql = "INSERT INTO `actions` (log) VALUES (?)"; $insa = $dbh->prepare($sql) or die $!; $insa->execute($line); print "Inserted Action!\n"; } &Loop; }

Also I want to add a way to delete the log file after it is uploaded to the db. Any suggestions?


In reply to Help w/ regex in filename by dcthehole

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.