[20004] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2199 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 25 00:10:43 2001

Date: Sat, 24 Nov 2001 21:10:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006665008-v10-i2199@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 24 Nov 2001     Volume: 10 Number: 2199

Today's topics:
        replacing certain 'bad' words globally <louisdepointedulac@theatredesvampires.freeserve.co.uk>
    Re: replacing certain 'bad' words globally <mgjv@tradingpost.com.au>
    Re: replacing certain 'bad' words globally <jeff@vpservices.com>
    Re: replacing certain 'bad' words globally <louisdepointedulac@theatredesvampires.freeserve.co.uk>
    Re: replacing certain 'bad' words globally <godzilla@stomp.stomp.tokyo>
    Re: replacing certain 'bad' words globally <louisdepointedulac@theatredesvampires.freeserve.co.uk>
    Re: replacing certain 'bad' words globally <godzilla@stomp.stomp.tokyo>
    Re: replacing certain 'bad' words globally <louisdepointedulac@theatredesvampires.freeserve.co.uk>
    Re: replacing certain 'bad' words globally <godzilla@stomp.stomp.tokyo>
    Re: replacing certain 'bad' words globally <godzilla@stomp.stomp.tokyo>
    Re: Using CGI.pm to obtain a list of params <wsegrave@mindspring.com>
    Re: variable scope <joe+usenet@sunstarsys.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 24 Nov 2001 23:29:28 -0000
From: "Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk>
Subject: replacing certain 'bad' words globally
Message-Id: <9tpal4$8iu$1@news6.svr.pol.co.uk>

Hi, joe newbie here, so bare with me!

i was after a script that i could customize to include a list of bad words
and a list of words to replace them with

and also this would need to be able to pick out the word anywhere on any
page and replace it there in situe

am i talking not doable?
many thanks for any pointers
Louis





------------------------------

Date: Sun, 25 Nov 2001 11:04:44 +1100
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <slrna00dcs.to2.mgjv@martien.heliotrope.home>

On Sat, 24 Nov 2001 23:29:28 -0000,
	Louis <louisdepointedulac@theatredesvampires.freeserve.co.uk> wrote:
> Hi, joe newbie here, so bare with me!

I'd rather keep my clothes on, thank you.

> i was after a script that i could customize to include a list of bad words
> and a list of words to replace them with

You could do something with hashes, probably. Hard to tell, since you
provide no indication about the number of words that you may be looking
for, or the amount of text that needs to be searched, or how that text
needs to be searched. You also fail to provide any clue on whether this
needs to be fast, or whether it can be slow (but possibly much easier to
maintain). You don't mention in what sort of form and magnitude this
data to be modified is provided. Line by line? It's also not clear
whether you want to preserve case or not.

> and also this would need to be able to pick out the word anywhere on any
> page and replace it there in situe

Any page?

To edit a file in-place, look at the -p, -n and -i command line flags to
Perl.

> am i talking not doable?

It's doable, but you haven't given enough information to even start
designing the outline of the program.

The approach in the Perl FAQ, under the question 'How do I efficiently
match many regular expressions at once?' may be sufficient for you (with
a replace instead of a match), but it's hard to tell. If you have to
process many megabytes of data and hundreds of words to be replaced,
then that approach may not be the best. Of course, it doesn't take
capitalisation into account. If none of those are problems, then
something like the following could be a starting point for you;

#!/usr/local/bin/perl -w
use strict;

my $text = <<EOT;
Some bad text with here and there a bad word that should be 
replaced with a less bad word. Of course, the meaning of 
the text hopefully doesn't change too much.
EOT

my %word = (
    'bad' => 'naughty',
    'word' => 'phrase',
    "doesn't" => 'does not',
);
my @repl = map { qr/$_/ } keys %word;

$text =~ s/\b($_)\b/$word{$1}/g for @repl;
print $text;


Martien
-- 
Do not pay any attention to what Godzilla says. It is a troll, and has 
no decent working knowledge of Perl or programming in general. Search 
groups.google.com to see a history of its posts and replies to these posts.


------------------------------

Date: Sat, 24 Nov 2001 16:03:10 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <3C00353E.663EE001@vpservices.com>

Louis wrote:
> 
> Hi, joe newbie here, so bare with me!

Oh, talking about nudity are you?  Harumph, no bare bodies here.  Better
filter out this message.

> i was after a script that i could customize to include a list of bad words
> and a list of words to replace them with

That's the hard part getting the list -- D^a^r^n or D##a##r##n or D AR N
or, well you get the idea ... there's a really, really large number of
ways to fool filters.

> and also this would need to be able to pick out the word anywhere on any
> page and replace it there in situe

That part is doable if it were possible to get a list in the first
place.

> am i talking not doable?

There you go again, talking about do do.  Watch your mouth pal. :-)

> many thanks for any pointers

Try the archives of this newsgroup (groups.google.com) where this
question has been asked many times and answered about as above.  If you
can settle for only the most obvious combinations of letters, then
search for "filter" and you can come up with hints on a script that will
work for the minimum, at least until your users decide to see how
"clever" they can be.

-- 
Jeff



------------------------------

Date: Sun, 25 Nov 2001 00:57:21 -0000
From: "Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <9tpfpt$bfr$1@news6.svr.pol.co.uk>

hi, and thanks for your responses
i think from my lack of info, you are thinking it may be more complicated
than it needs to be

basically it would be very few words here and there, it is more or less to
help replace words that i forget to change myself, it is a family site which
my relatives use (.htaccessed), so it is a precaution against any words i
might have missed, lots of pages you see.
 no users (family) are going to be entering offensive words, so i dont have
to worry about getting to clever with detection, just simply replacing a
list of words of my choosing and replacing them outright with a suitable
replacement, i dont think you can do what i want, as i would want it to be
automated, eg, lets say i uploaded an html file full of blasphemes and swear
words, i would want this to be automatically replaced with the words in my
list, still remaining where they are in situe, i had a look at that example
source that was inlcuded, but i dont know how to call or invoke that on a
given page, any clues, as that seems to be the angle i was after.

thanks again
Louis

"Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk> wrote in
message news:9tpal4$8iu$1@news6.svr.pol.co.uk...
> Hi, joe newbie here, so bare with me!
>
> i was after a script that i could customize to include a list of bad words
> and a list of words to replace them with
>
> and also this would need to be able to pick out the word anywhere on any
> page and replace it there in situe
>
> am i talking not doable?
> many thanks for any pointers
> Louis
>
>
>




------------------------------

Date: Sat, 24 Nov 2001 17:39:33 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <3C004BD5.AC13F2BC@stomp.stomp.tokyo>

Louis wrote:

> lets say i uploaded an html file full of blasphemes 


Why would a vampire worry about blasphemies?


Godzilla!


------------------------------

Date: Sun, 25 Nov 2001 02:09:25 -0000
From: "Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <9tpk11$ib2$1@newsg1.svr.pol.co.uk>

this is true trollbOy!

but, he would worry about them for the sake of his younger more
impressionable blood relations `vv`

Louis

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3C004BD5.AC13F2BC@stomp.stomp.tokyo...
> Louis wrote:
>
> > lets say i uploaded an html file full of blasphemes
>
>
> Why would a vampire worry about blasphemies?
>
>
> Godzilla!




------------------------------

Date: Sat, 24 Nov 2001 18:21:27 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <3C0055A7.879CF79@stomp.stomp.tokyo>

Louis wrote:
 
> but, he would worry about them for the sake of his younger more
> impressionable blood relations `vv`

 
Strikes an intelligent person such as myself,
a vampire would worry more about the stake
of his younger.


Godzilla!


------------------------------

Date: Sun, 25 Nov 2001 02:37:32 -0000
From: "Louis" <louisdepointedulac@theatredesvampires.freeserve.co.uk>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <9tpllo$qba$1@newsg4.svr.pol.co.uk>

but what a  stake  the world would be in if we have gotten to the  point
that we cant even filter out all the  bloody  swearing there is in this
modern age .
personally an able  bodied  being like myself could not give an  onion  for
all this swearing, as i know what it means and sometimes it just goes on for
what seems  forever so what if it is a hot  vampish  chick spouting these
words, i will not  stand  for my youngers taking these words to  heart

Louis

let the puns stop here>.

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:3C0055A7.879CF79@stomp.stomp.tokyo...
> Louis wrote:
>
> > but, he would worry about them for the sake of his younger more
> > impressionable blood relations `vv`
>
>
> Strikes an intelligent person such as myself,
> a vampire would worry more about the stake
> of his younger.
>
>
> Godzilla!




------------------------------

Date: Sat, 24 Nov 2001 19:03:07 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <3C005F6B.D0E442C5@stomp.stomp.tokyo>

Louis wrote:

> Godzilla! wrote:


> > > lets say i uploaded an html file full of blasphemes 

> > Why would a vampire worry about blasphemies?

> > > but, he would worry about them for the sake of his younger more
> > > impressionable blood relations `vv`

> > Strikes an intelligent person such as myself,
> > a vampire would worry more about the stake
> > of his younger.

> but what a  stake  the world would be in if we have gotten to the  point
> that we cant even filter out all the  bloody  swearing there is in this
> modern age .
> personally an able  bodied  being like myself could not give an  onion  for
> all this swearing, as i know what it means and sometimes it just goes on for
> what seems  forever so what if it is a hot  vampish  chick spouting these
> words, i will not  stand  for my youngers taking these words to  heart

> let the puns stop here.
 

Is it my lack of reflection which annoys you so?


Godzilla!


------------------------------

Date: Sat, 24 Nov 2001 19:38:50 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: replacing certain 'bad' words globally
Message-Id: <3C0067CA.5A79E84B@stomp.stomp.tokyo>

Godzilla! wrote:
 
> Louis wrote:
 
(topic is how to practice censorship)


This script below my signature will provide you
with a good beginning at censorship.

Presumptions are made your html file is of average
size and does not contain trick words to defeat
censorship. This script opens a file stored on
disk but could be converted to LWP use, with ease.

An average size web page can be read as a single line
file without any noticable speed nor memory penalities.
If you use LWP, a choice between slurping or line
reading is no longer an option.

This is a very simple method.

Add your own words to censor, as needed.


Godzilla!
--

#!perl

$display_file = "your/path/to/html/file";

undef ($/);

open (HTML, $display_file);
$html = <HTML>;
close (HTML);

$/ = "\n";

for (@Array)
 {
  ($key, $value) = split (/:/, $_);
  if ($html =~ /$key/)
   { $html =~ s/$key/$value/gi; }
 }

print $html;


@Array = ("but : butt ",
 " a : ah.. ah.. a ",
 " and : and.. hmm.. and ",
 " ever : ever and I mean EVER ",
 " get : get.. gitty up little doggies.. get ",
 "happy:HORNY",
 "hate :love ",
 " how : how, I don't know how. I am too old to remember how ",
 " no : yes ",
 " not : snot ",
 " hard : hard-on ",
 " here : uh.. uh.. here and there ",
 " if : ifins ",
 " is : iz ",
 " or : oar ",
 "right :wrong ",
 "sexual :sexual and, you know how much I love being sexual, ",
 "sex :sex and, you know how much I love sex, ",
 "stupid:smart",
 "sweet dreams:horrible nightmares",
 "think :thunk ",
 " tell : tail ",
 "that :dat ",
 "the :the.. uh.. oh yeah.. the ",
 "them :them there ones ",
 "this :dis ",
 "those :them there ones ",
 "turn :turn, hmm.. you know I've been thinking you really turn me on, well anyhow turn ",
 " what : watt ",
 " where : where, oh my gosh! I think Lon Chaney is the best werewolf ever! Well.. where ",
 "were :wu.. wu.. were ",
 "which:which witch",
 " work : work and, I really REALLY hate my job, ",
 "boy howdy:<font size=+2> Boy Howdy! </font> ",
 "btw:Bacon, Tomato & Watermelon Sandwich, ",
 "bye:ßuh ßuh ßuh ßuh ßye ",
 "catch ya guys later :catch ya guys later and, if I do catch you and get my hands on you, mmmm MMMMM... look out! ",
 "cya:See Later Alligator! Catch Ya In Awhile Crocodile! ",
 "good morning :good moaning ",
 "grin:silly grin",
 "ha! :<font size=+2>HA! HA! HA! HA!</font> ",
 " hey:Hey Moe! Hey Curly! Hey Larry! Hey ",
 "hug :BUGS",
 "huh:Did you know 'huh' spelled backwards is 'huh'? ",
 "hehe:NARF! NARF! ",
 "hello :Hello! Hello! Hello! ",
 "laughing:laughing and slobbering all over myself ",
 "lmao:Laughing My Big Fat Ass Off! ",
 "lol:Oh my gosh! I just had a wonderful orgasm! ",
 "poof:<font size=+2>FART!!</font> ",
 "rof:Flicking Boogers! ",
 "rotfl:Flicking Boogers! ",
 "smirk:drool",
 "snicker:slobber",
 " ur : OH MY GOD! A news report just said Uranus is surrounded by Klingons! Well, anyhow your ",
 "wink :oh.. oh.. I really need to winky tinky ",
 "banana :big firm erotic banana ",
 "believe :don't believe ",
 "big butt :tight teenage ass ",
 "brain :brain, incidently, have you ever eaten monkey brains? Well, anyhow ",
 "brother :brudder ",
 " car : car, which is a 1967 Ford Vomit with a throw up hood, ",
 "father :fadder ",
 " friend : sex partner ",
 " friends : sex parters ",
 " gorilla :gorilla, a large ugly humanoid like creature covered with body hair and often mistaken for a common human male, ",
 "laundry:laundry, which I don't like doing but when your dirty underwear start attacking your housecat, you need to do your laundry",
 "mother :mudder ",
 " man : knuckle dragging Neandertal man ",
 " men : knuckle dragging Neandertal men ",
 "woman :screaming hair pulling PMSing woman ",
 "women : screaming hair pulling PMSing women ",
 " who : who's on first who ",
 " you : yall ",
 "dick: <font size=+2> RICHARD! </font>",
 "shit:<font size=+2> DOG FART! </font>",
 "damn:<font size=+2> HOOVER DAM! </font>",
 "cunt:<font size=+2> BEAUTIFUL BABE! </font>",
 "bitch: <font size=+2> A SWEETHEART! </font>",
 "asshole:<font size=+2> HIGHLY INTELLIGENT PERSON! </font>",
 "motherfucker: <font size=+2> MUUUHAHAHAHAAAA! </font>",
 "fuck: <font size=+2> FOOK! </font>",
 "kira:Kira, the most beautiful and the most intelligent woman in our entire Universe,  ",
 "billy:Billy, a handsome man who is truly hung like a Clydesdale horse,  ",
 "penis:<font size=+2>RICHARD! RICHARD!</font>",
 "cock:<font size=+2>RICHARD! RICHARD!</font>",
 "pussy:<font size=+2>KITTY! KITTY!</font>",
 " ass :<font size=+2> ARSE! ARSE!</font>");

exit;


------------------------------

Date: Sat, 24 Nov 2001 18:21:24 -0600
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <9tpdp3$8fu$1@slb6.atl.mindspring.net>

"Alan J. Flavell" <flavell@mail.cern.ch> wrote in message
news:Pine.LNX.4.30.0111242146580.27752-100000@lxplus023.cern.ch...
> On Nov 23, William Alexander Segraves inscribed on the eternal scroll:
>
> > But this is Off-Topic of the ng, so I'll stop here.
>
> I'm still a bit confused by what you said, but I think the proper
> place to continue this is comp.infosystems.www.authoring.cgi, if I
> may.  Please look out for a followup there, and mind the Troll.
>

Thanks. I appreciate your followup.

I've been lucky enough to avoid it, KOW.

> (If you haven't posted there before, you'll need to consult
> http://www.thinkspot.net/ciwac/howtopost.html )
>

(I have)**2. FYI, I appreciate the willingness of the clpm experts to
participate in ciwac, as well, in spite of the obvious distractions.




------------------------------

Date: 24 Nov 2001 21:03:26 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: variable scope
Message-Id: <m3itbz7gk1.fsf@mumonkan.sunstarsys.com>

Bart Lateur <bart.lateur@pandora.be> writes:

> Perhaps that could be an addition to B::Xref, if it's not already in
> there. (n.b. invoke with "-MO=Xref" on the command line)

What I had in mind was something like C's lint, possibly with 
programmable "clauses" to indicate one's idea of "bad practice", 
but I'm not aware of anything that specifically addresses masked
lexicals.  B::Lint would be a natural candidate; something like 

  % perl -MO=Lint,no-masked-lex script.pl

might be nice here.  Somehow I'm skeptical that optree walking/
parsing is well-suited for this sort of thing, but I'll certainly 
look into B::Lint more closely.

OTOH, I find it strange that (AFAIK) there's no development suite
in Perl that's even remotely comparable to something as sophisticated 
as lclint.  I'd like to think this is simply an undesirable 
side-effect of working in an ever-evolving programming language, 
but I fear it's also endemic of the fact that Perl isn't often 
the language of choice for engineering a larger software project, 
where things like correctness proofs and multi-stage testing are 
absolutely essential.

[...]

> Two declarations, notice the line numbers marked with "i", but there's
> no mention of the scope size. Which $x is used on lines 5 and 7? It
> doesn't say.

Unfortunately I don't think B::Xref can be easily modified to keep 
track of the scope.  Here's a patch that lets you see how it walks 
the op tree; use it with something like

  % perl -MO=Xref,-r,-o-,-DO script.pl > /tmp/out

The output file is parseable; however, scope entry/exit is *not*
always properly reflected in the output.  In particular, enter* and 
leave* operations aren't always balanced correctly; I don't know how 
to fix this problem.  Anyway, here's the Xref.pm patch- 

--- Xref.pm.orig        Tue Jun 12 15:33:57 2001
+++ Xref.pm             Sat Nov 24 11:53:25 2001

@@ -109,7 +109,7 @@
 
 
 # Options
-my ($debug_op, $debug_top, $nodefs, $raw);
+my ($debug_op, $debug_top, $nodefs, $raw, $out_file);
 
 sub process {
     my ($var, $event) = @_;
@@ -161,6 +161,7 @@
 sub xref {
     my $start = shift;
     my $op;
+    local *STDERR = *STDOUT if $out_file eq "-";
     for ($op = $start; $$op; $op = $op->next) {
 	last if $done{$$op}++;
 	warn sprintf("top = [%s, %s, %s]\n", @$top) if $debug_top;
@@ -178,8 +179,8 @@
 	    xref($op->redoop);
 	    xref($op->nextop);
 	    xref($op->lastop);
-	} elsif ($opname eq "subst") {
-	    xref($op->pmreplstart);
+	} elsif ($opname =~ "leave") {
+            last;
 	} else {
 	    no strict 'refs';
 	    my $ppname = "pp_$opname";
@@ -229,6 +230,7 @@
 
 sub deref {
     my ($var, $as) = @_;
+    $var->[1] ||='';
     $var->[1] = $as . $var->[1];
     process($var, "used");
 }
@@ -297,6 +299,12 @@
     $top = UNKNOWN;
 }
 
+sub pp_enteriter {
+    my $op = shift;
+    $top = $pad[$op->targ] or return;
+    process($top, "intro");
+}
+
 #
 # Stuff for cross referencing definitions of variables and subs
 #
@@ -379,6 +387,8 @@
 	    last OPTION;
 	} elsif ($opt eq "o") {
 	    $arg ||= shift @options;
+            $out_file = $arg;
+            next if $arg eq "-";
 	    open(STDOUT, ">$arg") or return "$arg: $!\n";
 	} elsif ($opt eq "d") {
 	    $nodefs = 1;

-- 
Joe Schaefer       "We all agree that your theory is crazy, but is it crazy
                                           enough?"
                                               -- Niels Bohr



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 2199
***************************************


home help back first fref pref prev next nref lref last post