TapasranjanMohapatra wrote:
> All,
> My script goes like this...
> --------------------------------------
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> $cmd = "cat file_one";
> $content = qx!$cmd!;
> print "$content";
> --------------------------------------

You should not shell out to read a file, Perl is a full programming
language, you should use the builtin functions whenever possible.
Especially when they are common and simple ones. It is faster, safer,
and less bug/error prone.

#!/usr/bin/perl
use strict; # always
use warnings; # pretty much always

print "Content-type: text/html\n\n";

open my $HANDLE, 'file_one' or die "Can't open file for reading: $!";
while (my $line = <$HANDLE>) {
  print $line;
}
close $HANDLE;

The same thing only faster, much safer, and it will give you diagnostic
output in the error log of the web server to find out why it can't read
a particular file.  See the other poster's comments too.

http://danconia.org

> I have a case where file_one is not in the same directory. So I give the 
> absolute path of file_one
> in place of file_one. 
> When run it using perl on command line I get the contents of file printed 
> correctly.
> 
> But when accessed through browser (cgi-bin), I get nothing printed.
> 
> I thought it might be path problem , but it is not. Because when the file is 
> in same directory,
> it prints the content of the file.
> 
> Can anybody let me know where I am going wrong?
> TIA
> tapas
> 

-- 
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