in reply to Parse::RecDescent and <score: ...> directive
I think perhaps you are using an Atom Bomb to split a walnut. If your files are well formed and as simple as shown then something like this may be more appropriate:
#!/usr/bin/perl -w use strict; my $n; local $/; my $data =<DATA>; for my $network( split /(?=network:\w+)/, $data ) { my ( $net_loc ) = $network =~ m/network:(\w+)/; my ( $ip ) = $network =~ m/ip\s*=\s*([\d\.]+)/; my ( $mask ) = $network =~ m/mask\s*=\s*([\d\.]+)/; my %hosts = $network =~ m/host:(\w+)\s*=\s*{\s*([^;}]+)/g; $n->{$net_loc} = { ip => $ip, mask => $mask }; $n->{$net_loc}->{$_} = $hosts{$_} for keys %hosts; } use Data::Dumper; print Dumper $n; __DATA__ network:north = { ip = 10.1.1.0; mask = 255.255.255.0; host:asterix = {ip = 10.1.1.10;} host:obelix = {ip = 10.1.1.11;} host:idefix = {ip = 10.1.1.12;} host:ix_13_20 = {range = 10.1.1.13 - 10.1.1.20;} } network:south = { ip = 10.1.1.0; mask = 255.255.255.0; host:asterix = {ip = 10.1.1.10;} host:obelix = {ip = 10.1.1.11;} host:idefix = {ip = 10.1.1.12;} host:ix_13_20 = {range = 10.1.1.13 - 10.1.1.20;} } __END__ $VAR1 = { 'north' => { 'ip' => '10.1.1.0', 'asterix' => 'ip = 10.1.1.10', 'obelix' => 'ip = 10.1.1.11', 'idefix' => 'ip = 10.1.1.12', 'mask' => '255.255.255.0', 'ix_13_20' => 'range = 10.1.1.13 - 10.1.1.20' }, 'south' => { 'ip' => '10.1.1.0', 'asterix' => 'ip = 10.1.1.10', 'obelix' => 'ip = 10.1.1.11', 'idefix' => 'ip = 10.1.1.12', 'mask' => '255.255.255.0', 'ix_13_20' => 'range = 10.1.1.13 - 10.1.1.20' } };
cheers
tachyon
s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print
|
|---|