in reply to Match first word in line fails
With that said, here's my attempt:
#!/usr/bin/perl use strict; use warnings; my ($line, $cleanbook); my %badwords = (crud => "darn", shit => "shoot"); while ($line = <DATA>) { $line =~ s/["'.,!?:;\-()[\]{}|\\\/]/ /g; #replace all punctuation +with a space my @sentence = split(/\W+/,$line); @sentence = map {$badwords{lc($_)}?$badwords{lc($_)}:$_} @sentence +; $cleanbook .= join(' ', @sentence)."\n"; } print $cleanbook; __DATA__ "Crud," said Travis "Shit, this crud is shit!"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Match first word in line fails
by Anonymous Monk on Jan 31, 2005 at 17:47 UTC |