Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Re: Opening files problem

by mojobozo (Monk)
on Jul 30, 2002 at 18:37 UTC ( #186297=note: print w/ replies, xml ) Need Help??


in reply to Re: Opening files problem
in thread Opening files problem

Here you go (and yes, I'm absopositivilutely sure data.txt exists)... I have this data file:

This is the first line of the datafile. This is the second line of the datafile. This is the third line of the datafile. This is the last line of the datafile.
I also have this cgi file:
#!/usr/bin/perl print "Content-type: text/html\n\n"; &print_return_page_top; if (open (FILENAME, "data.txt")) { $line = <FILENAME>; while ($line ne "") { print "$line<BR>"; $line = <FILENAME>; } } else { print "Booger<br>"; } &print_return_page_bottom; ################################## sub print_return_page_top { print <<RETURN_PAGE_TOP; <HTML> <HEAD> <TITLE>This Reads And Prints A File</TITLE> </HEAD> <BODY BGCOLOR="#COCOCO" TEXT="#000000" LINK="#0000FF" VLINK="#9966CC" +ALINK="#FF0000"> <P>Hello, RETURN_PAGE_TOP } ################################### ################################## sub print_return_page_bottom { print <<RETURN_PAGE_BOTTOM; </BODY> </HTML> RETURN_PAGE_BOTTOM } ###################################
When I run the cgi file, the script does run. It prints an html page in IE and it says "Hello, Booger". I can't figure out why it's not opening the file. They are both in the same directory. In fact they're both in c:\Inetpub\wwwroot\CGI-BIN

In Internet Services Manager, the files are read and writebale. ISUSR has Guest access (I tried it with Admin access, same result). Nothing seems to work. A little more info:

Win2K Pro
IIS 5.0
ActivePerl (installed after starting IIS)
Running it all locally on localhost. I only have this capability, don't have another machine to try from.

Help me before I give up on perl again. I don't want to. I like perl, I really do.


Comment on Re: Re: Opening files problem
Select or Download Code
Re: Re: Re: Opening files problem
by Ferret (Scribe) on Jul 30, 2002 at 18:47 UTC

    Just looking at the code (haven't tried testing it), my first thought is to print the error from the open where you're printing 'Booger'.

    print "Booger: $!";

    Should print the error message from your open.

    Let me know what you get, and we can move on from there.

Re: Re: Re: Opening files problem
by graff (Chancellor) on Jul 31, 2002 at 02:18 UTC
    This part of your code:
    $line = <FILENAME>; while ($line ne "") { print "$line<BR>"; $line = <FILENAME>; }
    is more commonly expressed like this in perl:
    while (<FILENAME>) { print "<BR> $_"; }

    but I'm sure this has nothing to do with the problem you're having. The earlier advice about printing "$!" in the "Booger" message will help.

    It is possible that the cgi script is running with something other than "c:\Inetpub\wwwroot\CGI-BIN" as its current working directory (eg. it may be using wwwroot instead), so you might want to figure out how to determine the cwd, and include that info in the "booger" message (this would be "$ENV{PWD}" on unix, but I'm not sure if that ports to Windows) -- or maybe just experiment with opening "CGI-BIN\data.txt" to see if that works; certainly, if you use the full path name in the open statement, that should do it.

      SUCCESS!!

      graff was correct. I stuck in the $! on the print "Booger" and it told me that the file did not exist. Strange I thought, it's right there in the directory. So I moved a copy to the wwwroot and BINGO! Thanks for your help everyone. Not only am I learning Perl, but Windoze servers as well.

      Happy crunching!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://186297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (13)
As of 2014-08-21 13:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (135 votes), past polls