W
wmconlon
Really perplexed about reading a file line by line in a cgi script.
With one cgi parameter a subroutine does:
sub view {
my $file = $_[0];
open(TEXT, "<$file") or die "Can't open $file for preview";
while (defined ($text = <TEXT>)) {
....
This processes line-by-line.
Another cgi parameter invokes a different subroutine call which does:
sub add {
my $template_path=$_[0];
my $directory_path=$_[1];
my $name=$_[2];
open(TEXT, "<$template_path") or die "Can't open $template_path for
reading"; # open the template file
while( defined ($text = <TEXT>)) {
....
and reads the entire file into a single line, even though it is reading
the same file.
I guess it has something to do with scalar context, isn't
$template_path a scalar? I've battled this for a day, so it must be
something obvious.
With one cgi parameter a subroutine does:
sub view {
my $file = $_[0];
open(TEXT, "<$file") or die "Can't open $file for preview";
while (defined ($text = <TEXT>)) {
....
This processes line-by-line.
Another cgi parameter invokes a different subroutine call which does:
sub add {
my $template_path=$_[0];
my $directory_path=$_[1];
my $name=$_[2];
open(TEXT, "<$template_path") or die "Can't open $template_path for
reading"; # open the template file
while( defined ($text = <TEXT>)) {
....
and reads the entire file into a single line, even though it is reading
the same file.
I guess it has something to do with scalar context, isn't
$template_path a scalar? I've battled this for a day, so it must be
something obvious.