I don't think @names = $new_gecos; is doing what you want it to do. After that the @names array has only one entry, which makes the for loop after that a bit useless

And the regex might not do what you want it to do even if @names had more than one entry:

use Data::Dumper; @names=('de lowen','doe','de la mancha'); for $name (@names) { @comps = $name =~ m{(?:von|de la|de|van|der|le|el|la).*|\w+}g; } print Dumper(@comps);

prints out

$VAR1 = 'de la mancha';

If you want to add values to an array in a loop, use push . If you have many values in a scalar variable and want to split them to an array, use split.

And the most important thing: Test your code. Use Data::Dumper or simple print statements to show you what values are in your variables at different places in your program. You will be surprised how easy it is to find the bugs in your program.


In reply to Re: Best way to search content of an array by jethro
in thread Best way to search content of an array by walkingthecow

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.