This is not directly related to your question: I'm wondering if I'm missing something... Was there some special purpose to be served by this part of your code:
if (!$ARGV[0]) { print "Enter launch site! (don't forgot to include the \"http://\") +\n"; exit(0); } while (1) { exit(0) if(($target) && ($target eq $target)); $target = $ARGV[0] unless($target); ...
Or is it just meant to be equivalent to the following?
my $Usage = "$0 http://target.url\n"; die $Usage unless ( @ARGV == 1 and $ARGV[0] =~ m{^http://} ); $target = shift; ...
The point is that you don't need a while loop, especially not one that suggests iteration will continue indefinitely until some condition is met -- personally, I find the latter version more appropriate (and easier). Also, I can't imagine any situation where "$target eq $target" could ever be false (given that $target is a simple scalar string), so I don't understand why you would test that.

As another aside: some users might be grateful if it didn't insist that they type "http://" (and why not support "ftp://" as well) -- normal browsers have this flexibility:

die $Usage unless (@ARGV == 1 and $ARGV[0] =~ m{^((?:http|ftp)://)?(\w +*.*)}i and $2); $target = ( $1 ) ? shift : ( substr($2,0,3) eq "ftp" ? "ftp://$2" : " +http://$2"; ...
This version uses a grouping expression (?:http|ftp) which does not assign the matched region to a "capture variable" ($1, $2, etc); but if such a region is followed by "://", then that whole string (including the slashes) is assigned to $1. But even when nothing matches that first part of the regex, the remainder of the string (if any, and if it begins with something that matches \w) is always captured into $2. The assignment to $target is the whole arg if both capures were non-empty; otherwise, a suitable prefix is applied to $2 -- lots of ftp servers are using "ftp." as the first first part of the actual host name, whereas web servers now answer to "site.dom" as well as "www.site.dom".

The output of "perldoc perlre" is very long, but very rewarding to the careful reader. Browsing through that man page is time well spent.


In reply to Re: Extract substring from string with no whitespace using regexp? by graff
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.