you might want to look at "swatch", by Todd Atkins, to see how it is 
done there  ...

<http://www.oit.ucsb.edu/~eta/swatch/>

There is a File::Tail module which might work for you as well, or, at 
least show you another way to do it.

-s-


At 2:20 PM -0400 7/8/01, Jim Conner wrote:
>I am writing a script that is quite cool imo once I get it done. 
>But already I am seeing that it takes a ton of system resources. 
>Simply put, the script watches a log file (like tail -f) and then 
>reacts to certain things that occur.  I am thinking that the loop 
>that it is in might be taking up all the resources but that doesn't 
>quite jive with my knowledge of how this kind of thing works.  Here 
>is a snippet of the resource usage from top(3):
>
>Swap:  34236K av,   7268K used,  26968K free                 35756K cached
>
>   PID USER     PRI  NI  SIZE  RSS SHARE STAT  LIB %CPU %MEM   TIME COMMAND
>  8400 qadmin    17   0  3560 3560  1404 R       0 98.8  5.6   0:28 perl
>
>
>Here is a snippet of the part of the code that does the tail -f:
>
>
>if ( !chdir($qlogdir) ) {
>     print "Cannot read $qlogdir: $!\n";
>     return(undef);
>} else {
>     my $curpos;
>
>     &dmsg( __LINE__,
>           "Reading at end of Quake logfile: $qlogfile\n");
>
>     open(QLOG,$qlogfile)
>         or die("Unable to open $qlogfile: $!\n");
>
>     while ( <QLOG> ) {
>             $curpos++;
>     }
>
>     &dmsg( __LINE__, "Cursor Pos: $curpos\n");
>
>     # Following tail -f code provided by http://www.PerlMonks.org
>     # Monk unknown.
>
>     for ( ; ; ) {
>        my $vip       = 0;          # vote in progress
>         my $input;
>         my $timestart;              # Leave this here
>                                     # until I know I dont
>                                     # need it.
>          my $timestop;
>         my $player_name;
>         my $reqed_map;
>         my $command;
>
>         for ( $curpos = tell(QLOG) ;
>               $input  =     <QLOG> ;
>               $curpos = tell(QLOG) ) {
>             chomp $input;
>
>             if ( defined $input ) {
>                 &dmsg( __LINE__,"$input\n");
>             } else {
>                 &dmsg( __LINE__,
>                        basename($qlogfile) . " : EMPTY SET!\n");
>             }
>
>             $_  = $input;
>
>             ## START OUR SWITCH BLOCK!
>
>             switch: {
>
>                 ##
>                 # This next block for map voting.
>                 ##
>
>                   /.*] (.*): \!$keyword_map/ && do {
>                     $input           =~ /] (.*): \!($keyword_map) 
>([a-zA-Z0-9].*)/;
>                    ($player_name,
>                     $command    ,
>                     $reqed_map  )    = ($1,$2,$3);
>                     my $current_map  = &current_map;
>
>                         if ( !defined $reqed_map && $player_name ne 
>/[Cc]onsole/ ) {
>                           &usage("vote_assist");
>                         } else {
>                             # This is where we decide what kind of vote we are
>                             # in.  See comments.
>
>                             if ( $vote_type == 0 ) {
>                                 &type_votemap($reqed_map) if ( 
>$current_map eq $vote_map );
>
>                         } elsif ( $vote_type == 2 ) {
>                              # check what map we are in here.
>                             # then if we are in votemap, react :
>                              # or if we are in regular map, react
>                             ( $current_map eq $vote_map ) ? 
>&type_votemap   ($reqed_map):
> 
>&type_no_votemap($reqed_map);
>                         }
>
>                             sub type_votemap($) {
>                                my $funcName     = (caller(0))[3];
>                                my $reqed_map    =  shift;
>
>                                print STDERR "Now in $funcName\n";
>                                # This section will work in votemap ONLY and
>                                # players can only vote during this map.
>                                &map_vote($player_name,0,$reqed_map);
>                             }
>
>                             sub type_no_votemap($) {
>                                 my $funcName     = (caller(0))[3];
>                                 my $reqed_map    =  shift;
>
>                                 print STDERR "Now in $funcName\n";
>                                 # This section will work in any map and
>                                 # players can vote anytime during play.
>                                 # Must use vote session.
>                                 print STDERR "Requested map is: 
>$reqed_map from $funcName\n";
>                                 $vip            = &map_vote($player_name,1,
>                                                             $reqed_map   );
>                             }
>
>                         }
>                     };
>            last switch;
>
>             ## END OF SWITCH BLOCK!
>
>             if ( $vip ) {
>                 # Set my timestop (time limit for an active vote)
>                 ($timestart,
>                  $timestop)     = &get_seconds();
>                  print "Timestart is: $timestart and " .
>                        "timestop is: $timestop\n";
>             }
>
>         }
>
>         }
>         seek(QLOG, $curpos, 0);
>     }
>}
>
>
>
>
>
>- Jim
>
>-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-
>http://www.perlmonks.org/index.pl?node_id=67861&lastnode_id=67861
>
>-----BEGIN PERL GEEK CODE BLOCK-----      ------BEGIN GEEK CODE BLOCK------
>Version: 0.01                             Version: 3.12
>P++>*@$c?P6?R+++>++++@$M                  GIT/CM/J d++(--) s++:++ a-
>>++++$O!MA->++++E!> PU-->+++BD            C++++(+) UB++++$L++++$S++++$
>$C-@D!>++++(-)$S++++@$X?WP+>++++MO!>+++   P++(+)>+++++ L+++(++++)>+++++$ !E*
>+PP+++>++++n-CO?PO!o >++++G               W++(+++) N+ o !K w--- PS---(-)@ PE
>>*(!)$A-->++++@$Ee---(-)Ev++uL++>*@$uB+   Y+>+++ PGP t+(+++)>+++@ 5- X++ R@
>>*@$uS+>*@$uH+uo+w-@$m!                   tv+ b? DI-(+++) D+++(++) G(++++)
>------END PERL GEEK CODE BLOCK------      ------END GEEK CODE BLOCK------


-- 
------------------------------------------------
sandor w. sklar                |    Non impediti
unix systems administrator     |         ratione
stanford university itss-css   |    cogitationis
------------------------------------------------

Reply via email to