kiz has asked for the wisdom of the Perl Monks concerning the following question:
This outputs:#!/usr/bin/perl # Unicode entity text => Unicode decimal number %lookup = ("Adieresis" => 196, "Aring" => 197, "Ccedilla" => 199, "Eacute" => 201, "Ntilde" => 209, "Odieresis" => 214 ); # A few lines of text to test. # Only elements 4 and 6 should match @source = ("fred", "adieresis", "Adieresis", "&adieresis;", "&Adieresis;", "", "fr&Adieresis;ed" ); foreach (@source) { # regexp: [^;]+? matches 1+ characters which are not a semi-colon # ([^;]+?) Remember it (in $1) # &([^;]+?);? basically matches a (pseudo) entity s/&([^;]+);?/"&#".eval(exists $lookup{\1} ? $lookup{\1} : \1).";"/e; print "($1) $_\n"; }
which is not what I'm after.. it's finding matches, but not replacing it with anything the eval part, basically I'm sure that subsitution (either with s/// or tr///) should be able to do it, but I'm just not getting it.. :-( Anyone got anything that works? (am I barking at the wrong tree?) (should I even be barking here?) In hope....() fred () adieresis () Adieresis (adieresis) &#; (Adieresis) &#; (Adieresis) (Adieresis) fr&#;ed
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex & variable substitution
by holli (Abbot) on Jul 11, 2005 at 09:34 UTC | |
by kiz (Monk) on Jul 11, 2005 at 09:42 UTC | |
by holli (Abbot) on Jul 11, 2005 at 09:49 UTC | |
by kiz (Monk) on Jul 11, 2005 at 11:22 UTC | |
|
Re: regex & variable substitution
by neniro (Priest) on Jul 11, 2005 at 09:29 UTC | |
by kiz (Monk) on Jul 11, 2005 at 09:37 UTC | |
|
Re: regex & variable substitution
by kiz (Monk) on Jul 11, 2005 at 11:28 UTC |