Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Thought I'd put the words into some code as I thought of a use for it:)

#! perl -slw use strict; use constant LOGFILENAME => 'your logfile name goes here'; use constant CHUNKSIZE => 100; # Vary this to suit your application. open my $log, '<', LOGFILENAME or die $!; # Should use the constants here, but its easier to remember the number +s than # remember the names of the constants and which module to pull to impo +rt them. seek $log, 0, 2; my($lastsize, %events) = (-s LOGFILENAME); while(1) { my $size = -s LOGFILENAME; if ($size > $lastsize + CHUNKSIZE) { # Has the file grown (enough) +? my $line = <$log>; #Read the next available line my $now = time; # Record the time print $now, ' : ', $line; # Just for testing $lastsize += length $line; # remember the new position. if ($line =~ m[ICMP]) { # Check for condition # Schedule an event of met. push @{ $events{$now + 20} }, ['This condition occured 20 seconds ago', $line]; } elsif ($line =~ m[:137]) { push @{ $events{$now + 10} }, ['This condition occured 10 seconds ago', $line]; } } # Should give accuracy to within 1 sec by your systems clock. select undef, undef, undef,0.5; my $now=time; if (exists $events{$now}) { # Check for iminant events for my $event (@{ $events{$now} }) { # Process them all print $event->[0], $/, $event->[1]; } delete $events{$now}; # Remove them when done } }

Examine what is said, not who speaks.
1) When a distinguished but elderly scientist states that something is possible, he is almost certainly right. When he states that something is impossible, he is very probably wrong.
2) The only way of discovering the limits of the possible is to venture a little way past them into the impossible
3) Any sufficiently advanced technology is indistinguishable from magic.
Arthur C. Clarke.

In reply to Re: 'better mousetrap': how to perform timed event by BrowserUk
in thread 'better mousetrap': how to perform timed event by snafu

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-05-16 09:24 GMT
Find Nodes?
    Voting Booth?
    Perl 7 will be out ...

    Results (151 votes). Check out past polls.