David,

On Wednesday 25 July 2001 14:29, David Freeman wrote:
> open(NAMES,"/etc/mail/access") || die "Can't open access: $!\n";
> while (<NAMES>){
>          ( $email, $action )= split('', $_);
>          $newarray{$email} = $action;
> }
> close NAMES;

Okay, you ask how to split on a tab.  The first argument to split is a regex, 
so you can use "split /\t/" for your split.  This splits on a tab and, by 
default it uses $_, so you can leave that off.

> while(1){
>          print "Look for what domain in spam filter? ";
>          chomp($email=<STDIN>);
>          last unless $email;
>          print $newarray{$email},"\n";
> }

I have to believe that you're not showing us the whole program because by the 
time you get to this part of your code, %newarray would be out of scope.  So, 
I assume you've declared it outside of these while blocks.  If the key $email 
isn't in the %newarray hash you should get an error alerting you if you're 
using warnings - you are using warnings, aren't you?  And strict, use strict:

        use strict;
        use warnings;

So, you can do this if it's not in the array:

if( exists $newarray{$email} ){
        print $newarray{$email}, "\n";
}else{
        print "How you wanna handle this one? ";
        my $action;
        chomp( $action = <STDIN> );
        $newarray{$email} = $action;
}

Also, keep in mind that you don't have two arrays here, you have a single 
hash with a key and a value.  The key is the domain and the value is the 
action to take.

So, once you're done, you can just write this hash back to your file and 
you're done.  I'm not sure what the end bit of your program is doing, but I 
don't it's what you want to be doing.

Regards,

Troy Denkinger


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to