On May 22, Mark on GCI Server said:

>   I'm trying to populate an array from a file, I think I've got the array
>populated, however, I'm not sure. I then want to compare an input against
>the array to determine if its there, then look at the second component of
>each record. Any assistance would be greatly appreciated.

Do you really need to store the entire file in memory?

And from the sound of it, you'd probably want to use a hash, instead.

  open PASSWORDS, "< passwd" or die "can't read passwd: $!";
  while (<PASSWORDS>) {
    chomp;
    my ($username, $password) = split /=/;
    $pwd{$username} = $password;
  }
  close PASSWORDS;

  if (exists $pwd{$who}) {
    # $who was in the file
  }

You might not even need to store it in a hash:

  open PASSWORDS, "< passwd" or die "can't read passwd: $!";
  while (<PASSWORDS>) {
    chomp;
    my ($username, $password) = split /=/;
    if ($who eq $username) {
      # ...
    }
  }
  close PASSWORDS;

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
** I need a publisher for my book "Learning Perl's Regular Expressions" **

Reply via email to