Richard Lee wrote: > > why does below fail? > > ----- where it's failing ----- > open my $source, "<", "/tmp/server.log" > or die "Could NOT open /var/log/server.log: $!"; > my $file = new IO::Handle; > while ($_ = $file->getline($source) ) { > ---------------------------- > > Uncaught exception from user code: > usage: $io->getline() at ./watch_int1_2.pl line 126 > at /usr/lib/perl5/5.8.8/i386-linux-thread-multi/IO/Handle.pm line 411 > IO::Handle::getline('IO::Handle=GLOB(0x9af8c5c)', > 'GLOB(0x9b12380)') called at ./watch_int1_2.pl line 126 > main::shove_it() called at ./watch_server.pl line 98 > > > $io->getline > > This works like <$io> described in "I/O Operators" in perlop > <http://search.cpan.org/perldoc?perlop#I/O_Operators> except that > it's more readable and can be safely called in a list context but > still returns just one line. If used as the conditional +within a > |while| or C-style |for| loop, however, you will need to +emulate > the functionality of <$io> with |defined($_ = $io->getline)|.
The getline method of IO::Handle doesn't take a parameter. When you execute open my $source, '<', '/tmp/server.log'; you have created one IO::Handle object, and my $file = new IO::Handle; creates a second. Instead of $file->getline($source); You should be calling simply $source->getline; > I was trying to speed up my program which has to go through huge server > log (500Meg+) and when I was going over w/ > > while ($source) { > > } > > I discovered(from Dprof) that it was using up too much CPU(it's on old > system) and wanted to use a IO module to get down to lower level to gain > some speed but I am not too familiar w/ using modules.. can someone help on > this? If your process is CPU bound it's not going to go any faster unless you give the processor less to do, so IO::Handle won't help you. Show us what's inside the while loop and we may be able to help. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/