Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Usage of File::Tail::Multi generates conversion errors

by WaywardBuddha (Initiate)
on Nov 18, 2008 at 23:08 UTC ( #724418=perlquestion: print w/replies, xml ) Need Help??

WaywardBuddha has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks! I am trying to batch process syslogs from multiple firewalls in very close to realtime using File::Tail::Multi. Each device writes to its own syslog file, thus my need to have some form of multiple tails. The code is pretty straight forward in the example, but no matter what I push (in terms of syslog) into it, I get errors like this on each and every line:
Invalid conversion in printf: "%P" at ./systail line 89, <GEN0> line 6 +68899.
Line 89 in my proto-code is a simple:
The error is actually attached to the line, so it gets passed into the rest of the processing and pretty much wreaks havoc with my regex's etc. Here is a snippet of what I am working with (I changed the actual processing to a simple printf while I am troubleshooting):
### Set up the multitail handle for our logfiles $multitail=File::Tail::Multi->new ( Files => ["$logstring"], Debug => "0", Function => \&ProcessLogs, RemoveDuplicate => 0, ); for (;;) { $multitail->read; sleep 4; } exit 0; ### Log Processing Main Routine sub ProcessLogs { my $passed=shift; foreach my $line ( @{$passed} ) { chomp $line; printf("$line\n"); next if $line=~//; if ($line=~/Built/) { printf("Built\n"); } elsif ($line=~/Teardown/) { printf("Teardown\n"); } elsif ($line=~/Deny/) { printf("Deny\n"); } } }
Does anyone have any experience with tailing multiple files, or has used File::Tail::Multi that can offer some sage-like wisdom? This seems pretty straight forward, but after commenting out the "next if" line and rewriting this a few different ways, I am kind of lost here. Thank you!

Replies are listed 'Best First'.
Re: Usage of File::Tail::Multi generates conversion errors
by ikegami (Patriarch) on Nov 18, 2008 at 23:46 UTC

    The first arg of printf should be a formatting string.

    printf("%s", "$line\n"); # ok printf("%s\n", $line); # ok printf("$line\n"); # ERROR
    You want print.
Re: Usage of File::Tail::Multi generates conversion errors
by gwadej (Chaplain) on Nov 18, 2008 at 23:52 UTC

    It looks like you are using printf when you should be using print in the ProcessLogs. The print function doesn't need a format string, but printf requires one.

    G. Wade
Re: Usage of File::Tail::Multi generates conversion errors
by MidLifeXis (Monsignor) on Nov 18, 2008 at 23:21 UTC

    Does $line contain a '%P'?


Re: Usage of File::Tail::Multi generates conversion errors
by fmerges (Chaplain) on Nov 18, 2008 at 23:57 UTC


    Following MidLifeXis hint, printf expect to get a format, as the first argument, in your case that would be "$line\n", so whatever it's in $line + the "\n" will be used as the format, then it will try to substitute by the LIST of replacements, which is empty.

    Use print in all cases, except for those where you really want to have a specific format, where it comes handy to use printf.


    fmerges at
      I hate it when it is something so stupid... Simply changing it to a print worked fine. The script is really starting to come together now too. Thanks all!

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://724418]
Approved by ikegami
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2022-08-09 22:45 GMT
Find Nodes?
    Voting Booth?

    No recent polls found