On Mon, Mar 23, 2009 at 14:16, Amit Saxena <learn.tech...@gmail.com> wrote: > Is it possible to implement this without using any external modules from > CPAN ? > > Thanks & Regards, > Amit Saxena >
The FAQ covers this quite nicely (see below). In general you should use File::Tail[1]. And on UNIX systems, of course, you can always cheat: #!/usr/bin/perl use strict; use warnings; open my $pipe, "-|", "/usr/bin/tail", "-f", "./file.log" or die "could not start tail on file.log: $!"; print while <$pipe>; There are generally five reasons for not wanting to install modules: 1. they scare you (answer, get over it) 2. they scare your sysadmins (answer, work around them by installing in your home directory and use the lib[2] pragma) 3. you are using a hosting service that prevents you from installing modules (answer, get a better service, there are cheap services that don't behave like morons) 4. the target machine doesn't necessarily have the needed module (answer, use PAR[3] or PAR::Packer[4]) 5. the target machine is totally locked down (i.e. you login to rbash and have to provide code to a third party for inclusion on the box) Of the five, only the fifth is truly difficult to work around, but it is possible using the same techniques as the fourth with an added argument to the third party that they are willing to install other binary programs. from perldoc -q tail[5] First try seek(GWFILE, 0, 1); The statement "seek(GWFILE, 0, 1)" doesn’t change the current position, but it does clear the end‐of‐file condition on the handle, so that the next <GWFILE> makes Perl try again to read something. If that doesn’t work (it relies on features of your stdio implementation), then you need something more like this: for (;;) { for ($curpos = tell(GWFILE); <GWFILE>; $curpos = tell(GWFILE)) { # search for some stuff and put it into files } # sleep for a while seek(GWFILE, $curpos, 0); # seek to where we had been } If this still doesn’t work, look into the POSIX module. POSIX defines the clearerr() method, which can remove the end of file condition on a filehandle. The method: read until end of file, clearerr(), read some more. Lather, rinse, repeat. There’s also a File::Tail module from CPAN. 1. http://search.cpan.org/dist/File-Tail/Tail.pm 2. http://perldoc.perl.org/lib.html 3. http://search.cpan.org/dist/PAR/lib/PAR.pm 4. http://search.cpan.org/dist/PAR-Packer/lib/PAR/Packer.pm 5. http://perldoc.perl.org/perlfaq5.html#How-do-I-do-a-%27tail--f%27-in-perl%3f -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/