thanks
On Jan 11, 2008 5:04 PM, Jeff Pang <[EMAIL PROTECTED]> wrote: > On Jan 11, 2008 2:00 PM, Enjoy_Life <[EMAIL PROTECTED]> wrote: > > hi, who can tell me which is better of the following codes? > > why there are different methods to read files? > > thanks > > > > 1. open(INPUT, "< filedata") or die "Couldn't open filedata for > reading: > > $!\n"; > > while (<INPUT>) { > > print if /blue/; > > } > > close(INPUT); > > > > 2. use IO::File; > > $input = IO::File->new("< filedata") > > or die "Couldn't open filedata for reading: $!\n"; > > > > while (defined($line = $input->getline())) { > > chomp($line); > > STDOUT->print($line) if $line =~ /blue/; > > } > > $input->close(); > > > > Almost the same. > But using IO::File you get more methods to control the file > handler,like,to be monitored by select with many other handlers. > > From perldoc IO::File: > > "IO::File" inherits from "IO::Handle" and "IO::Seekable". It extends > these classes with methods that are specific to file handles. > > > -- > Jeff Pang - use Perl > [EMAIL PROTECTED] > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > -- ********************************************** ** Happy Everyday ** **********************************************