Leser: 17
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
28
29
30
#!/usr/local/bin/perl
use strict;
my %hash = ();
my @text;
open (AN, $ARGV[0] ) or die "$!\n";
open (IN, $ARGV[1]) or die "$!\n";
while (my $line = <AN>) {
chomp $line;
my ($k, $v) = split / /, $line;
$hash{$k} = $v;
}
my @vector = keys %hash;
wort_zu_zahl ();
sub wort_zu_zahl {
while (<IN>) {
chomp;
push (@text, split /\n/);
}
for my $line( @text ) {
chomp $line;
my @words = split / /, $line;
my %local = ();
$local{$_} += $hash{$_} for @words;
print join(",", map $local{$_} || 0, @vector),,"\n";
}
}
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/local/bin/perl use strict; use warnings; my $file_an=shift(@ARGV); my @files_in=@ARGV; my %hash = read_an($file_an); wort_zu_zahl($_,%hash) for(@files_in); sub read_an{ my $file=shift; my %hash=(); open(my $anfh, '<', $file) or die ("ERROR open $file ($!)\n"); while (my $line = <$anfh>){ chomp $line; my ($k, $v) = split /\s+/, $line; $hash{$k} = $v; } close($anfh); return %hash; } sub wort_zu_zahl{ my $file=shift; print "FILE: $file\n"; my %hash=@_; open(my $infh, '<', $file ) or die("ERROR open $file ($!)\n"); while(my $line= <$infh> ){ my %local = (); chomp $line; my @words = split /\s+/, $line; $local{$_} += $hash{$_} for @words; print join(",", map{$local{$_} || 0}keys(%hash) )."\n"; } close($infh); }
2010-03-28T13:56:26 mikey_b