On 3/7/06, Ryan Frantz <[EMAIL PROTECTED]> wrote:
>
>
> > -----Original Message-----
> > From: Curt Shaffer [mailto:[EMAIL PROTECTED]
> > Sent: Tuesday, March 07, 2006 11:06 AM
> > To: beginners@perl.org
> > Subject: mail list via script
> >
> > I have a need to mail 1000 users their usernames and passwords, this
> will
> > be
> > a 1 time thing. I was thinking that I could just do some sort of
> foreach
> > routine but I can't see how that will work when they will all be
> > different.
> > I then thought a hash with the usernames and passwords would be OK,
> but
> > then
> > how to I link the proper email account with the proper hash value. I
> am
>
> Since every key in a hash has to be unique, and every email address is
> unique, use the email address as the key in your hash:
>
> my %mailAccounts = (
>   [EMAIL PROTECTED] => 'abc123',
>   [EMAIL PROTECTED] => 'def456',
>   ...
> );
>

Depends on your setup. in most cases, it's the login name that will be
unique. There may be more than one accont associated with the same
email address. Individuals may have multiple accounts, husbands and
wives sometimes share email addresses, etc. So you'll probably want to
use the account as the key.

I'd go with a hash of hashes (HoH). something like the following:

    my %users;

    while (<DATA>) {
        chomp;
        my $user;
        my @user = split /\s+/, $_;
        $users{$user[0]}{email} = $user[1];
        $users{$user[0]}{pass} = $user[2];
    }

    foreach my $user (keys %users) {
        print "login is: $user\n";
        print "email is: $users{$user}{email}\n";
        print "password is: $users{$user}{pass}\n";
    }

    __DATA__
    unique1 [EMAIL PROTECTED]    abc123
    unique2 [EMAIL PROTECTED]   def345


That's a simple example--you'll want to streamline the assignments and
dereferencing--but it should get you started.

HTH,

-- jay
--------------------------------------------------
This email and attachment(s): [  ] blogable; [ x ] ask first; [  ]
private and confidential

daggerquill [at] gmail [dot] com
http://www.tuaw.com  http://www.dpguru.com  http://www.engatiki.org

values of β will give rise to dom!

Reply via email to