![]() |
![]() |
5 Einträge, 1 Seite |
if ( $rofl =~ /(?:hallo.*){2}/ ) {
$rofl =~ /.*(hallo).*(hallo).*/i
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
#!/usr/bin/perl -l use strict; use warnings; use Data::Dumper qw(Dumper); { my $boundary = 2; my $keyword = 'hallo'; my %table = map { $_ => join ' ', ($keyword, 'foo') x $_ } (0, 1, 2, 3, 4); my $does_match = sub { my ($str) = @_; my $occurences = 0; $occurences++ while $str =~ /(?:\A|\b)$keyword(?:\b|\z)/g; return { occurences => $occurences, match => ($occurences >= $boundary) ? 'yes' : 'no' }; }; print Dumper \%table; foreach my $often (sort { $a <=> $b } keys %table) { my $retval = $does_match->($table{$often}); print "occurences: $retval->{occurences}, match: $retval->{match}"; } }
1
2
3
4
5
6
7
8
9
10
11
12
13
$VAR1 = {
'4' => 'hallo foo hallo foo hallo foo hallo foo',
'1' => 'hallo foo',
'3' => 'hallo foo hallo foo hallo foo',
'0' => '',
'2' => 'hallo foo hallo foo'
};
occurences: 0, match: no
occurences: 1, match: no
occurences: 2, match: yes
occurences: 3, match: yes
occurences: 4, match: yes
QuoteCode (perl): (dl )(?:\A|\b)$keyword(?:\b|\z)
![]() |
![]() |
5 Einträge, 1 Seite |