in reply to Pattern match and fish out a entry from a hash
If I understand your issue correctly, perhaps the following will generate what you need:
use Modern::Perl; my %data = (); $data{b_slash_car_bit_slash_tebla_bit} = 'b/car[10]/tebla[9]'; $data{b_slash_car_bit_slash_tesla_bit} = 'b/car[10]/tesla[0] b/car[9]. +tesla[1]'; $data{b_slash_car_bit_slash_tisla_bit} = 'b/car[10]/tesla[0] b/car[9]. +tesla[1]'; my $var1 = 'b/car[*]/te.*a'; # <-- changed this to .* $var1 =~ s/\//_slash_/g; $var1 =~ s/\[\*\]/\_bit/g; # <-- changed _bit_ to _bit say /$var1/ ? 'YES' : 'NO' for keys %data;
Output:
YES YES NO
Each key of the hash is checked in the ternary statement for the pattern contained in $var1, resulting in printing "YES" if found, else "NO."
Hope this helps!
|
|---|