Link to home
Start Free TrialLog in
Avatar of paddytsr
paddytsr

asked on

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?
paddy
ASKER CERTIFIED SOLUTION
Avatar of binkzz
binkzz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rocca
rocca

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

chomp $ENV{QUERY_STRING};
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.
Avatar of paddytsr

ASKER

binkzz got there first
hes right about locking up questions with answers too
thanks binkzz
Binkzz - thanks.