in reply to Re^7: How to match more than 32766 times in regex?
in thread How to match more than 32766 times in regex?

or, rather
for my $str (@strs) { my $len = ( () = $str =~ m{ 0+ | 1+ }xg ) + ( $str =~ m{ 000 | 111 | (.)\1 .* (.)\2 }x ? 2 : $str =~ m{ (?: ^ (.)\1 | (.)\2 $) }x ? 1 : 0 ); print $len, "\n"; }
...anyway, I'm now too bored to think whether that's the correct solution and I'll leave the rest of that little programming exercise to you.

Your problem is that you're trying to write overly compact code even though you don't know Perl very well. And, naturally, writing the retarded equivalent of JAPHs is not a good way to learn Perl - or any programming language, for that matter. Just saying.

I recommended you to learn Forth a while ago, and I still do. BUK suggested Python, but its significantly more verbose than Perl and you won't like it.

Replies are listed 'Best First'.
Re^9: How to match more than 32766 times in regex?
by Anonymous Monk on Dec 02, 2015 at 06:21 UTC
    Mkay, I believe that's the final version:
    use strict; use warnings; use feature 'say'; use List::Util 'min'; my @strs = ( '0' x 1_000_000, '01' x 1_000_000, '011' x 1_000_000, '0110' x 1_000_000, ); for (@strs) { my $l = length(tr/01//sr); my $d = length() - $l; say $l + min( $d, 2 ); }