Leser: 19
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#!/usr/local/bin/perl -w # ############ $INFILE = "Beispiel.txt"; $OUTFILE = "output.txt"; open(FILEIN,"$INFILE") or die "Fehler beim Oeffnen von ".$INFILE."\n"; open(FILEOUT,"> $OUTFILE") or die "Fehler beim Oeffnen von ".$OUTFILE."\n"; while (<FILEIN>){ @Zeile = $_; while( ($schluessel, $wert) = each %hash) { if (@Zeile == $schluessel) { %hash = (@Zeile => +1); } else { %hash = (@Zeile => 1); } print "$schluessel => $wert\n"; } } close FILEIN; close FILEOUT;
perl -nE 'END{say"$_ => $n{$_}"for keys%n}chomp;$n{$_}++' input.txt >output.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/usr/local/bin/perl use strict; use warnings; my %hash; while (<DATA>){ chomp (my $zeile = $_); $hash{$zeile}++; } for my $wert (keys %hash) { print $wert . " => " . $hash{$wert} . "\n"; } __DATA__ blub blab blib blib blub bleb blfb