Hi Edward,

On Tue, 28 Sep 2004 11:20:39 -0400, Bob Showalter
<[EMAIL PROTECTED]> wrote:
> Edward Wijaya wrote:
> > Thanks a lot for your reply Bob.
> > but can you be more specific:
> >
> > > You need to either close and reopen the file, or
> > > rewind the file using seek() before you can re-read the data.
> > >
<< SNIP >>

Try this:

#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;

our $opt_f;
getopts('f:');

my $trial = 2;

for ( my $t = 1 ; $t <= $trial ; $t++ ) {
     print "Trial $t\n";
     open INFILE, "<$opt_f" or die "$0:  Can't open file $opt_f: $!";

     while (<INFILE>) {
         print;
     }
}

As a note, in the above code, you used a line:
  print "Trial ", $t, "\n";
But I changed it to:
  print "Trial $t\n";

The fun part of using double quotes (" ") is that Perl will
interpolate (think "translate") any variables inside those double
quotes that it finds!  Helps with reducing your typing AND has the
added benifit of making your code more readable!

When you use 'open' twice on the same file handle, it will first close
that file handle, then RE-open it with the input ready to go at the
beginning again!

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


Reply via email to