opening a file problem

i try to open a file in a perl script and this works...
open FILE,'<correct.txt' or die "can't open correct.txt because $!";

however when i pass the scipt the value 1.txt as a QUERY_STRING
like this
<a href="http://....cgi-bin/test.cgi?1.txt>click here</a>

and try....
open FILE,'</data/local/apache/htdocs/answers/$ENV{QUERY_STRING}' or die "can't
open /data/local/apache/htdocs/answers/$ENV{QUERY_STRING} because $!";

it wont work!!!
the error it reports is

can't open /data/local/apache/htdocs/answers/291119991.txt because No such file
 or directory at /usr/local/apache/cgi-bin/test.cgi line 46, <FILE> chunk 1

but the file is there and i have done chmod correctly (as far as i know)

can anyone help?
Who is Participating?
binkzzConnect With a Mentor Commented:
# Change your href to say ?file=1.txt

my $querystr = $ENV{"QUERY_STRING"};
my @queries = split (/&/, $querystr);

for (my $query=0; $query <= $#queries; $query++)
  my ($name, $value) = split (/=/, $queries[$query]);
  $querystring{$name} = $value;

open infile, "<$querystring{'file'}";
  @lines = <infile>;
  print @lines;
close infile;

# Try that
The problem is possibly that your QUERY_STRING likely has a trailing newline, if you do a "chomp $ENV{QUERY_STRING}" prior to trying to use the variable it should work...

open FILE,'</data/local/apache/htdocs/answers/$ENV{QUERY_STRING}' or die "can't
open /data/local/apache/htdocs/answers/$ENV{QUERY_STRING} because $!";

....or optionally what binkzz said should work too.
Rocca - Seeing you're not vey customed to Experts Exchange you might want to read the rules first.

It's uncustom and very inconvenient to answer a question rather than just supply your comment. You say it's 'possibly' an answer so why post it as one? Comments can be accepted as answers so you don't have to be afraid of losing out.

Besides that, prematurely answering will take the question away from other experts to have a look at as it's status will be locked.
paddytsrAuthor Commented:
binkzz got there first
hes right about locking up questions with answers too
thanks binkzz
Binkzz - thanks.
All Courses

From novice to tech pro — start learning today.