Thread parsen
(2 answers)
Opened by Gast at 2007-07-05 12:31
Ein kleiner Fehler war drin. So sollte es funktionieren:
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #!/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 @cats = $entry =~ /(cat=\d+)/g; my ($id) = $entry =~ /(ID=[^,;]+)/; next unless $id; push @{ $hash{$id} }, @cats; } } for my $key ( keys %hash ){ print $key, " - " , join(" : ", @{ $hash{$key} }),"\n"; } <!--EDIT|renee|1183625437--> 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/ |