Readers: 2
5 entries, 1 page |
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
#!perl -w use strict; use warnings; my @vorname; my $vorname; $vorname[0]= "Markus"; $vorname[1]= "Fritz"; $vorname[2]= "Otto"; my @liste; my $liste; $liste[0]= "Fritz"; $liste[1]= "Otto"; $liste[2]= "Fritz"; $liste[3]= "Josef"; my $zaehler = 0; foreach (@vorname) { if ("@liste" =~ "$_") { print "Der Vorname <<< $_ >>> ist vorhanden\n"; } else { print "Der Vorname <<< $_ >>> ist nicht vorhanden\n"; } }
1 2 3 4 5 6 7 8 9 10 11 12 13
use 5.010; use strict; use warnings; my @names = qw/Markus Fritz Otto/; my @candidates = <>; chomp @candidates; foreach my $name (@names) { my $count = scalar grep /\Q$name\E/, @candidates; say "'$name' encountered $count times"; }
1 2 3 4 5 6 7 8 9
for my $name (@vorname) { my $anz = grep{ $_ eq $name } @liste; if ( $anz ){ print "Der Vorname <<< $name >>> ist $anz Mal vorhanden\n"; } else { print "Der Vorname <<< $name >>> ist nicht vorhanden\n"; } }
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;
renee+2008-02-19 14:42:42--Code (perl): (dl )1 2 3 4 5 6 7 8 9for my $name (@vorname) { my $anz = grep{ $_ eq $name } @liste; if ( $anz ){ print "Der Vorname <<< $name >>> ist $anz Mal vorhanden\n"; } else { print "Der Vorname <<< $name >>> ist nicht vorhanden\n"; } }
5 entries, 1 page |