There is a modul on cpan that does what you want. It´s called File::Tail or something like that.
-----Ursprüngliche Nachricht----- Von: Andrew Curry [mailto:[EMAIL PROTECTED] Gesendet: Dienstag, 24. Juli 2007 12:12 An: Octavian Rasnita; Jeff Pang; beginners perl Betreff: RE: reading from a file If you want an over complex solution you could try using use IPC::Open3; use IO::Select; use IO::Handle; i.e. #!/usr/local/bin/perl -w use Data::Dumper; use File::Copy; use IPC::Open3; use IO::Select; use IO::Handle; use strict; use vars qw( $line $select $read $write $error ); ( $select, $read, $error ) = process_command('/usr/bin/tail -f tmp.dat'); process_tail($select); close_handles( $read, $error ); sub process_command { my ($command) = @_; my ( $pid, $readbuff, $timeout, $s ); $timeout = 10; $read = new IO::Handle; $error = new IO::Handle; $pid = open3( $write, $read, $error, $command ); # # create selects # $s = IO::Select->new(); $s->add($read); $s->add($error); return ( $s, $read, $error ); } sub process_tail { my ($select) = shift; my ( @ready, $handle, $timeout, $readbuff, $flag, $tapeloc, $newnum ); $flag = 0; # # get write handle # while ( $flag == 0 ) { @ready = $select->can_read($timeout); foreach $handle (@ready) { sysread( $handle, $readbuff, 256 ); # 256 is the number of chars to read. if ( length($readbuff) == 0 ) { $flag = 1; } } # # do something here # print "$readbuff\n"; } sleep(1); } sub close_handles { my ( $r, $e ) = @_; $r->close(); $e->close(); } Its not been tested so not sure if it will do what you require. -----Original Message----- From: Octavian Rasnita [mailto:[EMAIL PROTECTED] Sent: 24 July 2007 10:45 To: Jeff Pang; beginners perl Subject: Re: reading from a file From: "Jeff Pang" <[EMAIL PROTECTED]> > > --- Octavian Rasnita <[EMAIL PROTECTED]> wrote: > >> Hi, >> >> I am trying to read from a log file which increase continuously >> almost every second. > > You may try the Unix 'tail' command and pipe the result to your Perl > program.Like: > > tail -f access_log|perl -e > 'while(<>){handle_routine()}' > > handle_routine() is your routine for handling logfile lines. > > I can do this, but in that case I don't know how to be sure that I don't skip any line of the file. The condition is to not skip any line and to not get the same line twice. I tested the tail command in the command line using: tail -n 1 /path/to/file because I wanted to get only the last line of the file. If I use that command for more times, sometimes the same last line is printed for more times, but sometimes the tail command doesn't print anything. I don't know if the result of tail can be trusted... Thank you. Octavian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ This e-mail is from the PA Group. For more information, see www.thepagroup.com. This e-mail may contain confidential information. Only the addressee is permitted to read, copy, distribute or otherwise use this email or any attachments. If you have received it in error, please contact the sender immediately. Any opinion expressed in this e-mail is personal to the sender and may not reflect the opinion of the PA Group. Any e-mail reply to this address may be subject to interception or monitoring for operational reasons or for lawful business practices. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/