Thread parsen (2 answers)
Opened by Gast at 2007-07-05 12:31

renee
 2007-07-05 12:44
#78234 #78234
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
ungetestet:
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/usr/bin/perl

use strict;
use warnings;

my $file = '/path/to/file.txt';
my %hash;

{
    #Abschnitstrenner auf "\n\n", siehe perldoc perlvar
    local $/ = "\n\n"; 
    open my $fh, '<', $file or die $!;
    while( my $entry = <$fh> ){
        my ($cat,$id) = $entry =~ /(cat=\d+).*(ID=[^,]+)/s;
        push @{ $hash{$id} }, $cat;
    }
}

for my $key ( keys %hash ){
    print $key, " - " , join ":", @{ $hash{$key} },"\n";
}
OTRS-Erweiterungen (http://feature-addons.de/)
Frankfurt Perlmongers (http://frankfurt.pm/)
--

Unterlagen OTRS-Workshop 2012: http://otrs.perl-services.de/workshop.html
Perl-Entwicklung: http://perl-services.de/

View full thread parsen