Thank you very much for your detailed input!

In my case, there's not much more going on in the code and efficiency is not really a concern, as I'm working with very short lists of no more than maybe 5 elements or so. But I'd like to do things as "correctly" as possible which is why I was indeed looking to exit the lookup on the first match. Using first comes really in handy here, I'm glad that I asked as I obviously have a lot to learn about Perl. I'll be sure to read more about all these functions (thanks for the links!)/

I'm calling split since it's such a short string anyway that it just seems more than enough. Plus, I'm intentionally restricting myself to the core modules to learn Perl more properly before I go out using other solutions, if that makes sense. At least for now, of course, as I'm not really making anything significant or complex, just small scripts for my own use.

Just to clarify, this question refers to a simple script that can extract URL parameters out of a text file, with an option to provide the components to select from each match, like a specialized type of grep on the command line just for URLs:

xurl --select domain,route file1 file2 ... xurl --select proto,credentials file1 file2 ...

I'm taking my time to refine this script with better language features and cleaning it up, and this sort of questions come up from time to time.

Thanks again!


In reply to Re^2: Question about loops and breaking out of them properly by unmatched
in thread Question about loops and breaking out of them properly by unmatched

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.