in reply to Re: File Open Issue
in thread File Open Issue

Your code doesn't work, here is what I am trying:
use Cwd 'chdir'; chdir "../htdocs/"; open (FILE, "<$ENV{'PWD'}info.txt") || print "There is no file here in + $ENV{'PWD'}info.txt"; while ( my $line = <FILE> ) { chomp($line); #code.... }

Replies are listed 'Best First'.
Re^3: File Open Issue
by thundergnat (Deacon) on Jun 01, 2005 at 13:59 UTC

    Sigh. My fault for posting untested code.
    You are still missing the point about using Cwd. You don't need the chdir and you shouldn't rely on $ENV{PWD}. Here is a (tested) version showing what I mean.

    use warnings; use strict; use Cwd; my $curr_dir = cwd(); my $info_file = $curr_dir . '/../htdocs/info.txt'; open my $fh, '<', $info_file or die "Could not open file, $!"; while (my $line = <$fh>){ # process text }