in reply to Re^4: Array or Hash problem!
in thread Array or Hash problem!
#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
|
|---|