Leser: 1
![]() |
![]() |
5 Einträge, 1 Seite |
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
#!c:\perl\bin\perl.exe
use MLDBM qw(DB_File Storable);
use Data::Dumper;
my $dbfile = "test.db";
my $txtfile = "kw2005-02.txt";
my $zeile;
my $zeitraum;
my $suchbegriff;
my $anzahl;
my @spalten;
my %hash;
my %uniq;
tie %hash, 'MLDBM', $dbfile or die "Can&´t open $dbfile: $!\n";
open(INPUT, "< $txtfile") or die "Kann $txtfile nicht öffnen $!\n";
while(<INPUT>){
chomp;
$zeile = $_;
($suchbegriff,$anzahl) = split("\t",$zeile);
$zeitraum = $txtfile;
$zeitraum =~ s/kw//;
$zeitraum =~ s/.txt//;
$uniq{ $zeitraum } = $anzahl;
$hash{ $suchbegriff } = \%uniq;
}
print Dumper(\%hash);
untie %hash;
1
2
3
$href = exists $uniq{ $begriff } ? $uniq{ $begriff } : [];
push(@$href,$anzahl);
$hash{ $suchbegriff } = $href;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
[...] my @files = ("kw2005-02.txt", "kw2005-03.txt", "kw2005-03.txt") [...] foreach my $file (@files) { # Fuer jede File in @files open(INPUT, "< $file") or die "Kann $file nicht öffnen $! "; while(defined my $zeile = <INPUT>) { chomp $zeile; my ($suchbegriff,$anzahl) = split("\t",$zeile); my $zeitraum = $file; $zeitraum =~ s/kw//; $zeitraum =~ s/.txt//; $uniq{ $zeitraum } += $anzahl; # += Addiert $hash{ $suchbegriff } += \%uniq; } close(INPUT); }
use diagnostics;
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
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename qw/basename/;
my @files = @ARGV;
die "Syntax: " . basename($0) . " Datei1 [Datei2] [Datei3] ...\n" unless @files;
my @labels;
for my $file (@files) {
my ($label = basename($file)) =~ s~^kw(.+)\.txt$~$1~;
die "kann keinen Label zur Datei '$file' finden\n" unless defined $label and length $label;
push @labels, $label;
}
die "Anzahl Dateien und Anzahl Label sind unterschiedlich\n" unless @label == @files;
my %db;
for my $i (0 .. $#files) {
my $file = $files[$i];
my $label = $labels[$i];
open(F, $file) or die "Kann '$file' nicht oeffnen: $!\n";
while (<F>) {
chomp;
next if m/^\s*$/;
my ($suchbegriff, $anzahl) = split("\t",$zeile);
$db{$suchbegriff}->{$label} = $anzahl;
# oder: push @{ $db{$suchbegriff}->{$label} }, $anzahl;
}
close F or warn $!;
}
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
print Dumper \%db;
![]() |
![]() |
5 Einträge, 1 Seite |