your first fragment should work. try passing a "|| die $!" at the end of the open call, to make sure you have read permissions on it if it keeps failing. try something like this much cleaner):

die $! unless open F,"test.txt";
print reverse <F>;
close F;
 

printing <PASSWD> in the second example won't work--in this syntax you are printing $_ to the filehandle PASSWD (which you opened read only). if you are running with warnings turned on ($^W != 0 or perl -w) you will get a runtime warning (compile time warning in 5.6). You are using strict and -w right?

the bigger questions, of course, are why are you printing the contents of the password file to an HTML page? and are you print the content type as required for cgi scripts?

darren


In reply to Re: file access by dlc
in thread file access by kingboa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.