APM: question on variable scope
Jonathan Scott Duff
perlpilot at gmail.com
Tue Apr 15 20:17:11 PDT 2008
On Tue, Apr 15, 2008 at 3:36 PM, Seth Miller <seth at animejunkie.org> wrote:
> 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
Other than the chomp, you might want to change your algorithm from O(n^2) to
O(n)-ish by using a module like Regexp::Assemble to generate a single regex
to apply against your hash.
It would look something like this:
#!/usr/bin/perl
use warnings; use strict;
use Regexp::Assemble;
# ...
my $regex = Regexp::Assemble->new( file => $wordlist);
while (my($user,$pass) = each %data) {
print "$user - $pass\n" if $pass =~ $regex;
}
__END__
I don't know if it'll make a difference to what you're trying to do really,
but it's something you might want to try.
cheers,
-Scott
--
Jonathan Scott Duff
perlpilot at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/austin/attachments/20080415/4ca8e2a9/attachment.html
More information about the Austin
mailing list