in reply to smartmatch with multiple search values

I am unsure about what you intend. Some code below.
I highly recommend against using experimental features except for "fun code".
#!/usr/bin/perl use strict; use warnings; my $VAR1 = [ '11', '14' ]; #create a hash... my %owner_grouprights = map{$_=>1}@$VAR1; if ($owner_grouprights{'11'}) { print "test3-> 11 exists as a groupright\n"; } # you say: "the big deal -- if it only would work" WHAT?? ### what do you expect??? if (grep{/4|5|6|7|8|9|10|11|12/} keys (%owner_grouprights)) { print "test2->some number exists as a groupright\n"; #11 exists } # with loop my $testarrorig = '4|5|6|7|8|9|10|11|12'; my @testarr = split( /\|/, $testarrorig ); foreach my $tst ( @testarr ) { if (exists $owner_grouprights{$tst}) { print "$tst hit!\n"; } } __END__ test3-> 11 exists as a groupright test2->some number exists as a groupright 11 hit!
Update: I am very circumspect about smart match. Sometimes this critter is too smart! And produces unexpected results. I don't see the need for it in the above code.

Replies are listed 'Best First'.
Re^2: smartmatch with multiple search values
by toohoo (Beadle) on Jul 18, 2019 at 07:15 UTC

    Hello marshall,

    thanks for the hints, there are some real good points.

    One is you did the same thing with the match, same as Hippo above. Thanks

    A very good hint is the one with the hash. Thanks.

    The last one again is a loop. Some say this is not elegant ... But it works so far.

    Thanks for all, regards.