Go read How do I post a question effectively? first. Have you? Homework? Hm.

Next, more accurately the sentence should read "my name is <name> and I live in <continent>", 'cause that Bush bloke doesn't live in e.g. Venezuela.

Read up s/// for sub/sti/tute/.

You have a list of patterns, and a list of replacements. To tie them together in a convenient way there's hashes (see perldata). You could write

%hash = ( America => 'country', France => 'country', 'George Bush' => 'name', );

and so on. Writing 'country' over and over is tiresome. It seems easier to key the hash with the replacement patterns and have anonymous arrays as values (see perlref):

%hash = ( country => [ 'USA', 'France', 'Austria', 'Israel'], name => [ 'Georg Bush', 'Marie LePen', 'Jörg Haider', 'Ehud O +lmert'], ... );

Having set up that structure, let's go. Suppose we'll reading from a file, have it open and the filehandle FH ready for reading:

while (defined(my $line = <FH>)) { # read one line into $line while(my($repl,$ary) = each %hash) { # iterate over %hash foreach my $token(@$ary) { # @$ary: dereference the array +in $ary $text =~ s/$token/<$repl>/g; # substitute each token with ha +sh key } } print $line; # done }

This is an example to start with, there are more and probably better ways to do it. Read up the operators s///, m//, y// and tr// in perlop, and perlretut, perlre for more about regular expressions.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

In reply to Re: Replacing Types by shmem
in thread Replacing Types by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.