in reply to code problem

regardless of the rationale behind the code, this should work:
$FILE = "/path/to/file"; open (FH, $FILE) || die "Content-type: text/html\n\nCan't access file +$FILE"; print "Content-type: application/octet-stream\n\n"; while(<FH>) { print <FH>; } close (FH);

Replies are listed 'Best First'.
Re: Re: code problem
by blue_cowdawg (Monsignor) on Jul 21, 2003 at 18:02 UTC

    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. BergholdBrewer of Belgian Ales
    Peter@Berghold.Netwww.berghold.net
    Unix Professional
      > Which I believe is more what you wanted.
      s'not what i wanted, s'what the other guy wanted :)