toohoo has asked for the wisdom of the Perl Monks concerning the following question:
Hello all,
is there a way to search other than loop with smartmatch for multiple search values?
My code below
best regards
#!/usr/bin/perl use v5.10; use experimental 'smartmatch'; no warnings 'experimental::smartmatch'; $VAR1 = [ '11', '14' ]; my @owner_grouprights = @$VAR1; if ( '11' ~~ @owner_grouprights ) { print "test3\n"; } # the big deal -- if it only would work if ( {4|5|6|7|8|9|10|11|12} ~~ @owner_grouprights ) { print "test2\n"; } my $owner_grouprights = join( ' ', @owner_grouprights ); # with loop my $testarrorig = '4|5|6|7|8|9|10|11|12'; my @testarr = split( /\|/, $testarrorig ); my $testarr = join( ' ', @testarr ); foreach $tst ( @testarr ) { given( $tst ) { when ( @owner_grouprights ) { print "$_ hit!\n"; } default { #print "$_ miss\n"; } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: smartmatch with multiple search values
by hippo (Archbishop) on Jul 16, 2019 at 14:09 UTC | |
by toohoo (Beadle) on Jul 18, 2019 at 06:45 UTC | |
|
Re: smartmatch with multiple search values
by daxim (Curate) on Jul 16, 2019 at 18:35 UTC | |
by toohoo (Beadle) on Jul 18, 2019 at 06:54 UTC | |
by daxim (Curate) on Jul 18, 2019 at 12:52 UTC | |
|
Re: smartmatch with multiple search values
by haukex (Archbishop) on Jul 16, 2019 at 14:56 UTC | |
|
Re: smartmatch with multiple search values
by dsheroh (Monsignor) on Jul 17, 2019 at 07:27 UTC | |
by toohoo (Beadle) on Nov 19, 2019 at 08:09 UTC | |
|
Re: smartmatch with multiple search values
by Marshall (Canon) on Jul 17, 2019 at 06:52 UTC | |
by toohoo (Beadle) on Jul 18, 2019 at 07:15 UTC |