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
#!/usr/bin/perl use strict; use warnings; my $filename = 'DateiMitStringsDrin.txt'; my @array = (); if (open my $file, '<', $filename) {my @lines = <$file>; close $file; # Zeilenumbrüche entfernen chomp @lines; my %test = (); for (@lines) {# prüfen, ob NICHT in %test vorhanden (unless) unless (exists $test{ $_ }) {# ins Array schieben push @array, $_; # in %test merken $test{ $_ } = 1; } } } # test print $_."\n" for @array;
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my %hash; for (qw( foo bar bar foo ber foo bir foo bor foo bur )) { $hash{$_} ++; } print Dumper \%hash;