#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
$context="hi this is a test";
print "Content-type:text/html\n\n";
&getRandom($context);
sub getRandom {
s{<script[ >].*?</script>¦<noscript[ >].*?</noscript>¦<!--.*?-->}{}isg;
s{<.*?>(.*?)</.*?>}{}sg;
split(/\b/);
$randomword = $_[rand($#_ - 1)];
print $randomword;
}
In the split function the string is split by
\b, which is a "word boundary". This, however, results in spaces and such being captured as their own 'words'. You may want to replace \b with an actual match of word delimiting characters you want to target. Perhaps something like this might work better: split(/[^[:alnum:]]+/); And, while you're at it... the
rand() function should actually be: $randomword = $_[rand($#_ + 1)];