Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Opening files problem

by mojobozo (Monk)
on Jul 30, 2002 at 17:56 UTC ( #186279=perlquestion: print w/ replies, xml ) Need Help??
mojobozo has asked for the wisdom of the Perl Monks concerning the following question:

I'm rather new here, so please pardon me if I am missing an obviously simple (to you) answer. Please view my scratchpad for the details, but here's a rough run through:

My friend gave me some perl scripts to play with. One of them reads from a file and prints the file in a web page generated on the fly. The scratchpad has the files. The web page is being made, but nothing is being read to it (other than the "else" stuff).

Any help would be appreciated. There are more details regarding my machine and what not on the pad.

Thanks,
mojobozo

Comment on Opening files problem
Re: Opening files problem
by vek (Prior) on Jul 30, 2002 at 18:04 UTC
    Your open command is failing therefore executing the else portion of the code. Are you sure data.txt exists and exists in whatever directory your cgi script is running in?

    -- vek --
Re: Opening files problem
by DamnDirtyApe (Curate) on Jul 30, 2002 at 18:33 UTC

    Could you please post your code as a reply to your question, rather than leave it on your scratch pad? The contents of your scratch pad may change over time, making any future analysis of the questions-and-answers given in this thread useless.


    _______________
    D a m n D i r t y A p e
    Home Node | Email
      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.

        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.

        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.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2014-12-20 15:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (96 votes), past polls