in reply to check 2 string arrays

_ is not part of the \b character class. TMTOWTDI:
use strict; use warnings; my @array1 = qw (abc_RCF_BM_allocation_0_kl aplc_RCF_BM_allocation_0_in_nml fbe_RCF_BM_allocation_0_in_tvg ap_hu_BM_allocation_0_in_nml); my @array2 = qw(RCF_BM_allocation_0_in BM_allocation_0 RCF_BM_allocation_0); for my $pattern (@array2) { my @results = grep /$pattern/, @array1; print "$pattern is in @results\n"; }
Update: This detects BM_allocation_0 even when it is part of RCF_BM_allocation_0, but it is unclear what is required here.

Replies are listed 'Best First'.
Re^2: check 2 string arrays
by sharan (Acolyte) on Mar 31, 2009 at 13:21 UTC
    Hi cdarke, I tried with
    for my $pattern (@array2) { my @results = grep /$pattern/, @array1; print "$pattern is in @results\n"; }
    But i still have some error.e.g. it shows 2 outputs for some strings
    abc_RCF_BM_allocation_0_kl contains BM_allocation_0 abc_RCF_BM_allocation_0_kl contains RCF_BM_allocation_0 aplc_RCF_BM_allocation_0_in_nml contains RCF_BM_allocation_0_in aplc_RCF_BM_allocation_0_in_nml contains BM_allocation_0
    Still i didnt get what could be the problem.