Try it this way:
#! perl -slw use strict; use Data::Dump qw[ pp ]; my %config; while( <> ) { chomp; my @bits = split '[:|=]'; my $ref = \%config; $ref = $ref->{ shift( @bits ) } //= {} while @bits > 2; $ref->{ pop @bits } = pop @bits; } pp \%config;
Produces:
C:\test>969796.pl 969796.dat { "cfs_online_timeout_changes" => 200, "max_configured_packages" => 100, "max_reformation_duration" => 300, node => { nodeA => { interface => { lan900 => { ip_address => { IP_A => +{ name => "IP_A", netmask => "255.255.255.0" } }, name => "lan900", status => "up", }, lan901 => { ip_address => { IP_C => +{ name => "IP_C", netmask => "255.255.255.0" } }, name => "lan901", status => "up", }, }, name => "nodeA", status => "up", subnet => { SUBNET_A => { name => "SUBNET_A", st +atus => "up" }, SUBNET_B => { name => "SUBNET_B", st +atus => "up" }, }, }, nodeB => { interface => { lan900 => { ip_address => { IP_B => +{ name => "IP_B", netmask => "255.255.255.0" } }, name => "lan900", status => "up", }, lan901 => { ip_address => { IP_D => +{ name => "IP_D", netmask => "255.255.255.0" } }, name => "lan901", status => "up", }, }, name => "nodeB", status => "up", subnet => { SUBNET_A => { name => "SUBNET_A", st +atus => "up" }, SUBNET_B => { name => "SUBNET_B", st +atus => "up" }, }, }, }, }
In reply to Re: Parsing structured text, problem with parsing logic
by BrowserUk
in thread Parsing structured text, problem with parsing logic
by hperange
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |