in reply to Re: reading from file.
in thread reading from file.

Unless the script is long running the hash solution is still sub optimal. Read the name, then look through the file, will on average read half the file for a valid name. The hash solution must always read the entire file. A better way to store the file could improve things even more, but perhaps we get silly...

Cheers,
R.

Pereant, qui ante nos nostra dixerunt!

Replies are listed 'Best First'.
Re^3: reading from file.
by kcott (Archbishop) on Nov 14, 2013 at 07:12 UTC

    I noted there was insufficient information. I asked whether multiple attempts were allowed. I presented a clearly stated potential solution.

    Allowing multiple attempts is the norm. I raised the absence of code to achieve this (i.e. while loop) along with a lack of any handling of a successful login attempt.

    Both the array and hash solutions read the entire file; obviously, this is not something specific to the hash solution. The point I made was that this was only done once regardless of the number of attempts.

    -- Ken

      The code that I put up here isnt the exact code I am using. I generally just wanted the idea of what to do. Thats why it was typed. See I have a text file with the below data and must be done in that format, was reading into hashes seems the way to go, but will just arrays work to. The exact problem I have is. I am trying to ask a user for the username and password and retrieve them from the file and continue with the program if they validate.
      name1 pass1 name2 pass2