Your next is not inside the grep's block (which is "{ $_ eq $component }"), so it doesn't apply to it, only to the for - and in any case I wouldn't try to affect a grep or map with those control keywords. I would suggest of thinking of map and grep as always applying to the whole list, and it's also best practice for their blocks not to have any side effects.

If you wanted to apply them to only part of the list, I would suggest filtering the list with grep first, or e.g. a slice. For anything more complex, use a for loop.

Another common use case, which might apply in your case, is wanting to know from grep whether there is any match in the list, and stopping the search after that first match, for efficiency. This can be done with e.g. first or any from the core module List::Util. (Update: And apparently Perl is getting builtin any and all.)

In general, you should use Text::CSV / Text::CSV_XS for parsing CSV instead of split, and if I am understanding your code correctly, my node Building Regex Alternations Dynamically might be a technique that's useful to you as well, as regexes could perhaps be faster than a linear search in an array. Update 2: Also Fletch has an excellent point about using a hash in the reply below.

Minor edits for clarity.


In reply to Re: Question about loops and breaking out of them properly (updated) by haukex
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.