You have ...

foreach (@results) { if ($_ =~ m/(http\:\/\/).+/) { print "URL found: ".$_,"\n"; } }

The reason the "default variable", $_, exists is to simplify chunks of code which all operate on the same variable by eliminating explicit reference to the variable. Admittedly, some people question whether this is simplification and clarification, or obfuscation, but that's a separate discussion thread. As far as your code is concerned, I suggest it is pointless to assign to the default variable in the loop constrtuct, and then explicitly state the variable within it.

Either make use of the way the various functions use the default variable:

foreach (@results) { if (/(http\:\/\/).+/) { print "URL found: "; print; print "\n"; } }

Or else use a variable and give it a meaningful name. This is the more robust, as it allows you to use other constructs which could generate default variables, without worrying about the outer value being trashed, and more importantly, conveyes meaning to readers.

foreach $url (@results) { if ($url =~ m/(http\:\/\/).+/) { print "URL found: " . $url, "\n"; } }

P.S.: Back in the 70's, people dropped optional spaces from their BASIC programs, since it made it possible to fit more code into the 8K or 16K available RAM. Now that your CPU has more cache than that, use the spaces you need to make that print statement easily readable.

--
TTTATCGGTCGTTATATAGATGTTTGCA


In reply to coding standards by TomDLux
in thread Extract substring from string with no whitespace using regexp? by Elijah

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.