Leser: 1
|< 1 2 >| | 11 Einträge, 2 Seiten |
'xx556xx' ---> qw(xx 55 6 xx)
my @Array = keys %{{$String =~ m/((.)\2*)/g}}
1
2
3
4
5
my %count;
my $max;
for (split //, $string) {
$max = $count{$_} if ++$count{$_} > $max;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
use strict;
use warnings;
use Benchmark qw(:all);
my $s = 'xx55111111116jkwhcxxxxx';
sub test1 {
my $r;
my $r0;
my @R;
for my $c (split '', $s) {
unless (defined $r) {
$r = $c;
$r0 = $c;
} elsif($c eq $r0) {
$r .= $c;
} else {
push @R, $r;
$r = $c;
$r0 = $c;
}
}
push @R, $r if length $r;
@R;
}
sub test2 {
keys %{{$s =~ /((.)\2*)/g}}
}
sub test3 {
my @x = $s =~ m/((.)\2*)/g;
map $x[2*$_], 0..@x/2-1;
}
cmpthese (-20,
{
for => \&test1,
pKai => \&test2,
murphy => \&test3,
}
);
1
2
3
4
Rate for murphy pKai
for 5172/s -- -12% -27%
murphy 5866/s 13% -- -18%
pKai 7123/s 38% 21% --
my @sequences = $string =~ m/((??{'(.)\1*'}))/g;
QuoteWARNING: This extended regular expression feature is considered highly experimental, and may be changed or deleted without notice. A simplified version of the syntax may be introduced for commonly used idioms.
|< 1 2 >| | 11 Einträge, 2 Seiten |