in reply to Getting around "/" as a word boundary
my $pat = join '|', keys(%hashstore); $doc =~ s!\b($pat)\b!$1/$hashstore{uc($1)}!ig;
You're wrong about the negative lookbehind not working.
my %hashstore = ( "DEXX" => "AREX", "AREX" => "CUBE" ); my $doc1 = "DEXX"; my $doc2 = "DEXX"; my $doc3 = "DEXX"; #foreach (keys %hashstore){ foreach ("DEXX", "AREX"){ # Make sure we get them in the worse order. $doc1=~s#\b($_)\b#$1/$hashstore{uc($_)}#ig; } #foreach (keys %hashstore){ foreach ("DEXX", "AREX"){ # Make sure we get them in the worse order. $doc2=~s#(?<!/)\b($_)\b#$1/$hashstore{uc($_)}#ig; } my $pat = join '|', keys(%hashstore); $doc3 =~ s!\b($pat)\b!$1/$hashstore{uc($1)}!ig; print("$doc1\n"); # DEXX/AREX/CUBE print("$doc2\n"); # DEXX/AREX print("$doc3\n"); # DEXX/AREX
Note the addition of uc(). Without it, you'd match stuff you wouldn't find in the hash because of /i.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting around "/" as a word boundary
by AnomalousMonk (Archbishop) on Aug 12, 2010 at 05:01 UTC | |
|
Re^2: Getting around "/" as a word boundary
by renshui (Novice) on Aug 12, 2010 at 08:34 UTC | |
by AnomalousMonk (Archbishop) on Aug 12, 2010 at 08:48 UTC | |
by ikegami (Patriarch) on Aug 12, 2010 at 16:14 UTC |