Hallo!
Wie kann ich ein Element in ein Array einfügen, wenn es nicht schon im Array vorhanden ist?Ganz konkret: In einer while-Schleife bekomme ich z.B. 20 mal $beispiel="hallo", 30 mal $beispiel="problem" und 10 mal $beispiel="hilfe".
Im Array soll aber nur stehen:
@beispielarray=("hallo","problem","hilfe");Gibt es da eine einfache Lösung?
#!/usr/bin/perl
my %hash;
@hash{"hallo","problem","hilfe"} = ();
my @input = ("hallo","problem","hilfe", "hallo","problem","hilfe","hallo","problem","hilfe");
foreach(@input)
{
$hash{$_}++;
}
foreach(keys %hash)
{
print "$_ kam $hash{$_} mal vor.\n";
}