APM: question on variable scope

Seth Miller seth at animejunkie.org
Tue Apr 15 13:36:35 PDT 2008


Hello all,

I've having some trouble with a script.  I'm trying to grab a complete
list of email accounts on the server and check the password against a
word list to find weak passwords.  The hash %data has the email
address in the key and the account password in the value.

The word list file currently just has the word 'password' for testing
but it doesn't seem to be working.  Here's the portion of the script
that's not working

#BEGIN

open (WORDLIST, "<$wordlist") or die "Can't open the wordlist: $!";

while (my $pass = <WORDLIST>) {
  while ( my ($user,$password) = each (%data) ) {
    print "$user - $password\n" if ($password =~ /$pass/);
  }
}

close WORDLIST;

#END

The while loop that iterates through the word list is working because
if write a die to spit out the value of $pass, it prints the word
password as expected.  If I change the if statement to if ($value =~
/password/) it works too.

Also if I set the value of $pass manually just before the print line,
it works.  The script just doesn't work as it looks above.  No errors
or warnings, just no output.  I'm assuming it has something to do with
the scope of the $pass variable.

Any ideas?

--seth


More information about the Austin mailing list