> -----Original Message-----
> From: David Freeman [mailto:[EMAIL PROTECTED]] 
> Sent: Wednesday, July 25, 2001 2:29 PM
> To: [EMAIL PROTECTED]
> Subject: First Script Question
> 
> 
> 
> Hi all, i've been receiving the list mail for a few days and 
> read through 
> what people seem to need to look at to help others with 
> script problems. I 
> included what little bit of code i have for my project below. 
> Basically i've been going through the Perl by Example book 
> and pulling 
> relevant bits out to piece this together.  I want to 
> eventually turn this 
> into a web script, but not yet.
> 
> I want this script to be able to open the /etc/mail/access file, read 
> through it and sort the hopefully 2 columns into seperate arrays. the 
> e-mail/domain names to be blocking in the first array and the REJECT, 
> RELAY, 500 Message in the second array.  It asks for user 
> input of "which 
> doamin to look for" in the list already and runs through to 
> see if it has a 
> match.  At the moment when i put in a name i know is in there 
> it comes back 
> with the REJECT, which is out of array 2.  The list is 
> seperated by tabs, 
> and (honestly) i don't know what to put in the delimeter 
> field to make it 
> look for a tab to seperate.
> 
> The harder question i have is the second half of the script.  Once it 
> determines that no match was found, i want to have it 
> appended to the end 
> of array 1, ask for another user input for "How should we 
> treat this email 
> / domain name?" in which user fills in REJECT, RELAY, etc. 
> and then close 
> the access file with changes made.
> 
> and that's sort of where i'm reading as much as i can and code stops.
> 
> Thanks for any advise!
> 
> 
> #!/usr/bin/perl -w
> #Script to add spam to /etc/mail/access file
> #And create and hash of it then restart sendmail
> 
> open(NAMES,"/etc/mail/access") || die "Can't open access: 
> $!\n"; while (<NAMES>){
>          ( $email, $action )= split('', $_);

If the fields are separated by a single tab char, use /\t/ as the first
argument to split. Using a null string will split into individual
characters. Also, naming $_ in your split() call is unnecessary, as $_ is
the default. This is documented in:

   perldoc -f split

>          $newarray{$email} = $action;

Your description above keeps saying "array", but you realize that newarray
here is a hash, not an array, right?

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

If you want to test whether an entry for $email exists in %newarray, use the
exists() function:

   perldoc -f exists

> }
> 
> if <STDIN> <> $email
> open(APPEND, ">>/etc/mail/access1") || die "can't open 
> access1 $!\n"; APPEND=<STDIN> print APPEND "<STDIN>  \n";

I have no idea what this code is supposed to be doing.

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

Reply via email to