mulander has asked for the wisdom of the Perl Monks concerning the following question:
In this code he first creates a list of bad_words that he want's to search for, then creates a list of good_words to subsitute instead of the found bad ones. He gives the str_replace the bad and good words only telling him on what string it should work on.$bad_words = array('ugly', 'anotherugly'); $good_words = array('ug**','anot******y'); $txt = 'ugly anotherugly'; $txt str_replace($bad_words, $good_words, $txt);
It works fine, but I am wondering about a few things, that are beyond my kwnoledge.#!/usr/bin/perl use warnings; use strict; my %words = ( ugly => 'ug**', anotherugly => 'anot*******', ); my $txt = "ugly anotherugly"; $txt =~ s/$_/$words{$_}/g foreach %words; print $txt;
|
|---|