On Jan 11, 5:28 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
> Enjoy_Life 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();
>
> I suggest that best of all is:
>
> use IO::Handle;
>
> open my $input, '<', 'filedata' or die "Couldn't open filedata for
> reading: $!";
>
> while (my $line = <$input>) {
>    next unless $line =~ /blue/;
>    print $line;
>
> }
>
> Note the following:
>
> - die() will not show the program file and line number where it was
>    called if there is a newline at the end of its string parameter.
>

Is this...

die "Couldn't open filedata for reading: $!\n";

The string parameter?


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to