Date: Fri, 18 Jun 2004 09:24:22 -0700 From: Bill Campbell <freebsd@celestial.com> To: "freebsd-questions@FreeBSD. ORG" <freebsd-questions@FreeBSD.ORG> Subject: Re: perl script code Message-ID: <20040618162422.GA75750@alexis.mi.celestial.com> In-Reply-To: <MIEPLLIBMLEEABPDBIEGMECHGDAA.Barbish3@adelphia.net> References: <MIEPLLIBMLEEABPDBIEGMECHGDAA.Barbish3@adelphia.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040618162422.GA75750>