2014-11-28T21:51:23
RhoenSprudelJetzt meine Frage: Kann ich nicht einfach den kompletten Block ab "interface" bis zum nächsten in ein Array speichern?
Ja.
QuoteDer Rest der "interfaces" wäre dann in den anderen Teilen des Arrays. Mir würde es helfen, wenn ihr mir erklären könnt, wie ich diesen "Block" in ein Array speichern kann.
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:
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__
Information 1a
Information 1b
Information 1c
Information 2a
Information 3a
Information 3b
Information 1a
Information 1b
Information 1c
Information 2a
Information 3a