in reply to Mass Text Replacement
The above seems to work, but if you have 5000+ keys, that's going to take a huge amount of time to code and run about as fast as a one-legged dog. There's also the problem that it's easy to write inefficient regexes.my $data = <<EOT; This is just lines of text here, and also there. Consider this human readable text; it's full of letters and punctuation. EOT my %table = ( '\b[Ll]ines of text\b' => "foo.html", '\b[Tt]his\b' => "bar.html", '\b[Ii]t\'?s full\b' => "foobar.html" ); $data =~ s/($_)/<a href="$table{$_}">$1<\/a>/g foreach keys %table; print $data;
The other idea that comes to mind is using the String::Approx module to try to match the keys to text. The problem with that is that it will be slower and more error prone :(
tedv wrote:
Of course, we link the initial This but not the this starting line 2.Why "of course"? Can you explicitly state a rule? Are you only trying to match the first occurrence of each string? If so, take off the /g on the substitution and it will work much faster.
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|