perl script code
Bill Campbell
freebsd at celestial.com
Fri Jun 18 09:24:23 PDT 2004
On Fri, Jun 18, 2004, JJB wrote:
>I have this
>
>
> #("Scan line for word abuse,");
>
> if ((/(abuse\@.*?)\s/) || (/(anti-spam\@.*?)\s/))
> {
> if (${1} eq "abuse\@slt.lk>") { $abuse_email =
>"abuse\@slt.lk"; next; }
> if (${1} eq "abuse\@sunrise.net>") { $abuse_email =
>"abuse\@sunrise.net"; next; }
> if (${1} eq "abuse\@tele2.it>") { $abuse_email =
>"abuse\@tele2.it"; next; }
> if (${1} eq "abuse\@swip.net>") { $abuse_email =
>"abuse\@swip.net"; next; }
> if (${1} eq "abuse\@tiscali.fr\"") { $abuse_email =
>"abuse\@tiscali.fr"; next; }
> if (${1} eq "abuse\@cpcnet-hk.com\"") { $abuse_email =
>"abuse\@cpcnet-hk.co"; next; }
> if ((${1} =~ /\@apnic.net/i) || (${1} =~ /\@lacnic.net/i))
> {
> next;
> }
> else
> {
> $abuse_email = ${1};
> debug("abuse_email body = $abuse_email\n");
> }
> }
>
>How can I rewrite the
> if (${1} eq "abuse\@slt.lk>") { $abuse_email =
>"abuse\@slt.lk"; next; }
> if (${1} eq "abuse\@sunrise.net>") { $abuse_email =
>"abuse\@sunrise.net"; next; }
> if (${1} eq "abuse\@tele2.it>") { $abuse_email =
>"abuse\@tele2.it"; next; }
> if (${1} eq "abuse\@swip.net>") { $abuse_email =
>"abuse\@swip.net"; next; }
> if (${1} eq "abuse\@tiscali.fr\"") { $abuse_email =
>"abuse\@tiscali.fr"; next; }
> if (${1} eq "abuse\@cpcnet-hk.com\"") { $abuse_email =
>"abuse\@cpcnet-hk.co"; next; }
>
>part so I can check the last position of what ever is found for > \
>/ ) } ] and delete those unwanted characters from value that gets
>loaded into $abuse_email???
This type of thing is generally better handled using a hash for
the test, something like:
# This just loads 1 into the hash for each address. One might
# want to generalize by mapping to the real abuse address.
my %addrmap = map { $_, 1 } qw(
abuse at slt.lk
abuse at sunrise.net
abuse at tele2.it
abuse at swip.net
abuse at tiscali.fr
abuse at cpcnet-hk.com
);
# $1 will be all no-whitespace after the ``@''
if(/abuse\@(\S+) && $addrmap{$1) {
($abuse_email = $1) =~ s/>*$//; # strip trailing '>'(s)
}
...
Bill
--
INTERNET: bill at Celestial.COM Bill Campbell; Celestial Software LLC
UUCP: camco!bill PO Box 820; 6641 E. Mercer Way
FAX: (206) 232-9186 Mercer Island, WA 98040-0820; (206) 236-1676
URL: http://www.celestial.com/
``Virtually everything is under federal control nowadays except the
federal budget.''
-- Herman E. Talmadge, 1975
More information about the freebsd-questions
mailing list