Thread Wörter im Array zählen (4 answers)
Opened by wiederlader at 2008-02-19 15:34

pq
 2008-02-19 15:49
#106105 #106105
User since
2003-08-04
12208 articles
Admin1
[Homepage]
user image
es geht auch mit nur einer schleife:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
use Data::Dumper;
my @vorname = qw/ Markus Fritz Otto /;
my @list = qw/ Fritz Otto Fritz Josef /;
my %treffer;
my $re = join "|", @vorname;
for my $entry (@list) {
    if ($entry =~ m/^($re)\Z/) {
        $treffer{$1}++;
    }
}
print Dumper \%treffer;
Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live. -- Damian Conway in "Perl Best Practices"
lesen: Wiki:Wie frage ich & perlintro Wiki:brian's Leitfaden für jedes Perl-Problem

View full thread Wörter im Array zählen