Thread Newbie - Einlesen von Text in arrays (18 answers)
Opened by PatrickS at 2004-12-27 15:24

renee
 2005-01-04 08:19
#50380 #50380
User since
2003-08-04
14371 Artikel
ModeratorIn
[Homepage] [default_avatar]
Dann würde ich eher einen Hash of Hashes machen, und den Ursprung als Schlüssel...
Code: (dl )
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
#! /usr/bin/perl

use strict;
use warnings;

my %hash;
while(my $line = <DATA>){
 my %inner_hash;
 foreach my $item(split(/,/,$line)){
   my ($key,$val) = split(/=/,$item);
   $key =~ s/[^\w]//g;
   $val =~ s/[^\w&]//g;
   $inner_hash{$key} = $val;
 }
 push(@{$hash{$inner_hash{URSPRUNG}}},\%inner_hash);
}

foreach my $key(keys(%hash)){
 foreach my $elem(@{$hash{$key}}){
   my ($base,@vols) = split(/&/,$elem->{VOL});
   foreach(@vols){
     print $key," ",$elem->{CODE}," ",$base.$_,"\n";
   }
print $key," ",$elem->{CODE}," ",$base,"\n" unless(@vols);
 }
}
# _ _DATA_ _ ohne Leerzeichen!!
_ _DATA_ _
:URSPRUNG=123,CODE=320317440,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=3203177290,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=320317770,VOL=0&1&2&3&4&5&6&7&8&9!
:URSPRUNG=123,CODE=32021883,VOL=3&4&5!
:URSPRUNG=123,CODE=4203204,VOL=4&5&6&7!
:URSPRUNG=125,CODE=32021883,VOL=3&4&5!
:URSPRUNG=125,CODE=4203204,VOL=4&5&6&7!
:URSPRUNG=124,CODE=32021883,VOL=3&4&5!
:URSPRUNG=124,CODE=4203204,VOL=164564&5&6&7!
:URSPRUNG=124,CODE=4203206,VOL=124&5&6!


Ausgabe:
Quote
125 32021883 34
125 32021883 35
125 4203204 45
125 4203204 46
125 4203204 47
123 320317440 01
123 320317440 02
123 320317440 03
123 320317440 04
123 320317440 05
123 320317440 06
123 320317440 07
123 320317440 08
123 320317440 09
123 3203177290 01
123 3203177290 02
123 3203177290 03
123 3203177290 04
123 3203177290 05
123 3203177290 06
123 3203177290 07
123 3203177290 08
123 3203177290 09
123 320317770 01
123 320317770 02
123 320317770 03
123 320317770 04
123 320317770 05
123 320317770 06
123 320317770 07
123 320317770 08
123 320317770 09
123 32021883 34
123 32021883 35
123 4203204 45
123 4203204 46
123 4203204 47
124 32021883 34
124 32021883 35
124 4203204 1645645
124 4203204 1645646
124 4203204 1645647
124 4203206 1245
124 4203206 1246
\n\n

<!--EDIT|renee|1104819662-->
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 Newbie - Einlesen von Text in arrays