Thread Array-Block speichern
(3 answers)
Opened by RhoenSprudel at 2014-11-28 22:51 2014-11-28T21:51:23 RhoenSprudel Ja. Quote Naja, du liest die Datei einfach zeilenweise ein - und wenn ein neuer Blockanfang kommt, dann speicherst du das bisher gelesene in dem Array. Mir ist aber nicht klar, warum du das brauchst. Ich hab mal ein Beispiel gemacht: 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 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 use 5.14.0; sub endOfBlock { my ($iface, $ref_alsHoA) = @_; say "interface: $iface"; for my $k (sort keys %$ref_alsHoA) { say "$k: ", join ', ', @{$ref_alsHoA->{$k}}; } %$ref_alsHoA = (); } my %alsHoA; my $iface; while (<DATA>) { if (/^###### interface (.+) ######$/) { endOfBlock($iface, \%alsHoA) if defined $iface; $iface = $1; } if (/^(Information \d+)(.+)/) { push @{$alsHoA{$1}}, $2; } } endOfBlock($iface, \%alsHoA) if defined $iface; __DATA__ ###### interface INFORMATION1 ###### Information 1a Information 1b Information 1c Information 2a Information 3a Information 3b ###### interface INFORMATION2 ###### Information 1a Information 1b Information 1c Information 2a Information 3a |