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

Hi Monks, I am creating a blog posting website using perl but if i post something example like "Hey guys try this link: http://site.com/" i want the link to be detected and clickable i tried but i failed here's my code:
$query=qq{SELECT ....}; $queryhandle=$connect->prepare($query); $queryhandle->execute(); while(my $blog=$queryhandle->fetchrow_hashref()){ HTML::Entities:encode($blog->{blog_post}); for(split/ /, $blog->{blog_post}){ print "<a href='$_'>$_</a>" and next if $_=~m/^http/; } print "$_"; } print "<br />"; ...
but if you entered an enter character in your blog example: "hey guys try this link: http://site.com/<enter char>so nice!" yes it's clickable but the link is "http://site.com/so" it only stops in a space character any idea how to fix this? Thanks in advance!

Replies are listed 'Best First'.
Re: How to detect and make a link clickable Perl/CGI
by Your Mother (Archbishop) on Dec 15, 2015 at 13:42 UTC

    URI::Find (there are a couple of related and subclasses too).

      URI::Find i think that's the answer thank you for both you!
Re: How to detect and make a link clickable Perl/CGI
by Corion (Patriarch) on Dec 15, 2015 at 13:27 UTC

    Maybe you want to split the text not on spaces but on whitespace? See perlre for more information on character classes, especially \s.

    Also, what is your strategy to avoid people posting Hello! <script>window.location="htt" + "p://google.com?q=some+spam+site</script> ?

      That would be blocked by HTML::Entities i think

        Indeed - I hadn't seen that. Using HTML::Entities should prevent you from interpolating things that a browser interprets as HTML tags into your output.