Thread $rofl =~ /hallo{2,}/i
(4 answers)
Opened by Gast at 2007-07-18 15:49 Code (perl): (dl
)
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}"; } } Code: (dl
)
1 $VAR1 = { |