From owner-freebsd-questions@FreeBSD.ORG Fri Jun 18 16:24:23 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 42F5816A4CE for ; Fri, 18 Jun 2004 16:24:23 +0000 (GMT) Received: from mail.mi.celestial.com (dagney.celestial.com [192.136.111.7]) by mx1.FreeBSD.org (Postfix) with ESMTP id E305243D48 for ; Fri, 18 Jun 2004 16:24:22 +0000 (GMT) (envelope-from bill@celestial.com) Received: by mail.mi.celestial.com (Postfix, from userid 203) id 82D2D11E88C; Fri, 18 Jun 2004 09:24:22 -0700 (PDT) Date: Fri, 18 Jun 2004 09:24:22 -0700 From: Bill Campbell To: "freebsd-questions@FreeBSD. ORG" Message-ID: <20040618162422.GA75750@alexis.mi.celestial.com> Mail-Followup-To: "freebsd-questions@FreeBSD. ORG" References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i Subject: Re: perl script code X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: freebsd@celestial.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 18 Jun 2004 16:24:23 -0000 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@slt.lk abuse@sunrise.net abuse@tele2.it abuse@swip.net abuse@tiscali.fr abuse@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@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