bliako has asked for the wisdom of the Perl Monks concerning the following question:
I want to test whether some string contains exactly 2 occurences of something. But this does not work:
my $outs = <<'EOS'; A B C A B D EOS # ok(2 == $outs =~ m|A|gs, "checking exactly 2 matches"); if( 2 == $outs =~ m|A|gs ){ print "exactly 2 matches\n" }
Is it possible to force list context in a conditional?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: most terse regex match count
by haukex (Archbishop) on May 16, 2019 at 15:32 UTC | |
by Veltro (Hermit) on May 17, 2019 at 14:38 UTC | |
by haukex (Archbishop) on May 18, 2019 at 19:13 UTC | |
|
Re: most terse regex match count
by Fletch (Bishop) on May 16, 2019 at 15:32 UTC | |
|
Re: most terse regex match count
by jwkrahn (Abbot) on May 16, 2019 at 19:09 UTC | |
|
Re: most terse regex match count
by holli (Abbot) on May 17, 2019 at 09:30 UTC | |
by hippo (Archbishop) on May 17, 2019 at 09:52 UTC | |
|
Re: most terse regex match count
by Marshall (Canon) on May 17, 2019 at 05:49 UTC | |
by holli (Abbot) on May 17, 2019 at 09:39 UTC | |
by bliako (Abbot) on May 17, 2019 at 10:17 UTC | |
|
Re: most terse regex match count
by bliako (Abbot) on May 16, 2019 at 15:51 UTC | |
by LanX (Saint) on May 16, 2019 at 15:56 UTC | |
by bliako (Abbot) on May 16, 2019 at 16:15 UTC |