File Looping
Look at the following code, which is an analog of what
you have posted.
#!/usr/bin/perl -w
######################################################################
+##
use strict;
my $file=$0;
my $line=1;
open(FH,"$file") or die $!;
print "Content-type: text/plain\n\n\n";
while (<FH>) {
printf "%d:%s",$line++,<FH>;
}
When I run that I get:
--$ ./filetest.pl
Content-type: text/plain
1:####################################################################
+####
--$
To fix this I do the following:
#!/usr/bin/perl -w
######################################################################
+##
use strict;
my $file=$0;
my $line=1;
open(FH,"$file") or die $!;
print "Content-type: text/plain\n\n\n";
while (<FH>) {
printf "%d:%s",$line++,$_; # $_ vs. <FH>
}
Which yields:
--$ ./filetest.pl
Content-type: text/plain
1:#!/usr/bin/perl -w
2:####################################################################
+####
3:
4:use strict;
5:
6:my $file=$0;
7:my $line=1;
8:
9:open(FH,"$file") or die $!;
10:
11:print "Content-type: text/plain\n\n\n";
12:while (<FH>) {
13: printf "%d:%s",$line++,$_;
14:}
--$
Which I believe is more what you wanted.
Yeah... I know the close(FH) is missing at the end.
| Peter L. Berghold | Brewer of Belgian Ales |
| Peter@Berghold.Net | www.berghold.net |
| Unix Professional |
|