Thanks, i understand you
#INITIAL DATA my @code_array = qw( 7772344 2233421 TMW2222987 TMA2222333 TMW9999988 AMQ8873332 AMQ1111877 ); my @test_suite = qw( 2222987 7772344 TMW2222987 TMD2222333 bbb TMA 111 ); #CODE # this print "Variant 1:\n"; for (@test_suite) { printf "%s is %s\n", $_, /^(?:\w{3})?\Q$_\E$/ ~~ @code_array ? 'match' : 'not match'; } # or that variant print "\nVariant 2:\n"; for my $val (@test_suite) { printf "%s is %s\n", $val, (grep /^(?:\w{3})?\Q$val\E$/, @code_array) ? 'match' : 'not match'; }
Resulting:

Variant 1:
2222987 is match
7772344 is match
TMW2222987 is match
TMD2222333 is not match
bbb is not match
TMA is not match
111 is not match

Variant 2:
2222987 is match
7772344 is match
TMW2222987 is match
TMD2222333 is not match
bbb is not match
TMA is not match
111 is not match

In reply to Re^5: Array or Hash problem! by youlose
in thread Array or Hash problem! by Anonymous Monk

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.