keiusui has asked for the wisdom of the Perl Monks concerning the following question:

I have a string that contains numbers and numerous other characters:

$s = "Numbers: 89, 90, 91, 180";

How would I replace all of the numbers in $s so that it's value becomes something more helpful:

$s = "Numbers: <a href=\"http://www.89.com\">89</a>, <a href=\"http:// +www.90.com\">90</a>, <a href=\"http://www.91.com\">91</a>, <a href=\" +http://www.180.com\">180</a>";

Any help would be gratefully appreciated!

Replies are listed 'Best First'.
Re: replacing all strings of numbers with a link
by Zaxo (Archbishop) on Jun 21, 2006 at 01:13 UTC

    It's a straight global substitution,

    $s =~ s!(\d+)!<a href="http://www.$1.com">$1</a>!g;

    After Compline,
    Zaxo

      Awesome; thanks so much! I was missing the plus sign in my original code, so every single digit would be replaced instead of every string of digits. You rock.