Problem iterating over diamond (while<FILE>)
From: Edward Wijaya (ewijaya_at_singnet.com.sg)
Date: 09/28/04
- Next message: Gavin Henry: "Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news."
- Previous message: Gavin Henry: "Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news."
- Next in thread: Gavin Henry: "Re: Problem iterating over diamond (while<FILE>)"
- Reply: Gavin Henry: "Re: Problem iterating over diamond (while<FILE>)"
- Maybe reply: Bob Showalter: "RE: Problem iterating over diamond (while<FILE>)"
- Maybe reply: Bob Showalter: "RE: Problem iterating over diamond (while<FILE>)"
- Reply: Peter Scott: "Re: Problem iterating over diamond (while<FILE>)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 28 Sep 2004 22:37:19 +0800 To: "beginners@perl.org" <beginners@perl.org>
Hi,
Suppose I have a data file that contain these lines:
output1
output2
when I run the code below
with: perl mycode.pl -f datafile
it gives:
Trial 1
output1
output2
Trial 2
instead of:
Trial 1
output1
output2
Trial 2
output1
output2
Can we actually loop over the 'while diamond'?
Please kindly advice how can I overcome this problem.
Thanks so much for your time.
Regards,
Edward WIJAYA
SINGAPORE
__BEGIN__
use strict;
use warnings;
use Getopt::Std;
our $opt_f;
getopts('f:');
open INFILE, "<$opt_f" or die "$0: Can't open file $opt_f: $!";
my $trial = 2;
#What's wrong with running a for loop over the 'while' here?
for ( my $t = 1 ; $t <= $trial ; $t++ ) {
print "Trial ", $t, "\n";
while (<INFILE>) {
print;
}
}
__END__
- Next message: Gavin Henry: "Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news."
- Previous message: Gavin Henry: "Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news."
- Next in thread: Gavin Henry: "Re: Problem iterating over diamond (while<FILE>)"
- Reply: Gavin Henry: "Re: Problem iterating over diamond (while<FILE>)"
- Maybe reply: Bob Showalter: "RE: Problem iterating over diamond (while<FILE>)"
- Maybe reply: Bob Showalter: "RE: Problem iterating over diamond (while<FILE>)"
- Reply: Peter Scott: "Re: Problem iterating over diamond (while<FILE>)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]