Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
I'm trying to parse without success a file like this into an hash:
I can remove comments and empty lines:--> file begins # This is a comment and after is an empty line # Each key starts on a new line KEY1 => 'VALUE1' # This also is a comment KEY2 => { 'VALUE 21', 'VALUE 22', # Spaces in value are relevant 'VALUE 23' } --> file ends
But I don't know how to split the resulting string into the hash, so that it becomes:my $input_string = ''; while (@lines) { my $line = shift @lines; chomp $line; if ($line) { my @parts = split(/#/,$line); $input_string .= $parts[0]; } }
Thanks for suggestions.my %inp = ( KEY1 => 'VALUE1', KEY2 => { 'VALUE 21', 'VALUE 22', 'VALUE 23' } )
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Initialize an hash with string
by Eliya (Vicar) on Jun 21, 2012 at 09:41 UTC | |
by Anonymous Monk on Jun 21, 2012 at 09:45 UTC | |
Re: Initialize an hash with string
by rovf (Priest) on Jun 21, 2012 at 09:30 UTC | |
by Anonymous Monk on Jun 21, 2012 at 09:58 UTC | |
by rovf (Priest) on Jun 21, 2012 at 12:30 UTC | |
by Anonymous Monk on Jun 21, 2012 at 13:06 UTC | |
by rovf (Priest) on Jun 21, 2012 at 14:26 UTC | |
Re: Initialize an hash with string
by Anonymous Monk on Jun 21, 2012 at 12:58 UTC | |
Re: Initialize an hash with string
by zeni (Beadle) on Jun 21, 2012 at 09:48 UTC |
Back to
Seekers of Perl Wisdom