Monks,
I have once again come to harken at your gates for an answer to one of my many problems.

I just finished going through both the file input/output and looping tutorials and decided I'd try to write up a script that incorporated both aspects. I'm trying to create a simple login script, that prompts the user for his/her name and then the password, then runs a check to see if the names/passwords match; if they do then a file is opened and the lines displayed. I've gotten it to recognize correct/incorrect password/username identification, but I'm having trouble with the opening of the file. If the user/pass check is successfull the file does not open, and if it is unsuccessful it does not open. Maybe it's just too late for me to be attempting to script but here is what I've gotten thus far:
#!/usr/bin/perl -w my $cusr; $cusr=bob; my $cpword; $cpword=pass; print "What is your username? "; $usr=<>; chomp($usr); if($usr==$cusr){ print "One moment please...\n "; print "Please enter your password:\n "; $pword=<>; chomp($pword); if($pword==$cpword){ print "One moment please...\n "; print "Authentication Complete!\n "; } } if($pword==$cpword){ open (FILE, "memberlist.txt"); while(<FILE>){ push @lines,$_; close FILE; } } else{ print "ERROR: username or password incorrect, please try again\n " +; }
and specifically (or at least I'd assume specifically)where the problem lies, in the following lines :
if($pword==$cpword){ open (FILE, "memberlist.txt"); while(<FILE>){ push @lines,$_; close FILE; } }
That's it... and I can't seem to find the problem. Any help at all is immensly appreciated, and I ask that you please bare with me, as I am very very new to the world of Perl (and of programming on the whole) so if there's an obvious problem here please don't laugh too hard at my incompetence :).

Thank you again for your time monks, and again I appreciate any help you can give.

just my 5 cents (ran out of pennies!)

Edit: chipmunk 2001-11-04


In reply to Variable/if question... by tretin

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.