in reply to Parse data representing hash
Here is my humble attempt to solve your interesting puzzle:
use strict; use warnings; use Data::Dumper; my %hash; my @row; while(<DATA>){ my ($level, $word) = /^(\s*)(\w*)$/; $level = length($level)/4; $row[$level] = $word; $#row = $level; my $last = \%hash; for (0..$#row) { $last->{$row[$_]} = $_ == $#row ? undef : {} if not defined $last- +>{$row[$_]}; $last = $last->{$row[$_]}; } } print Dumper \%hash; __DATA__ one two three four five six
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Parse data representing hash
by peterp (Sexton) on Jun 29, 2014 at 18:47 UTC |
In Section
Seekers of Perl Wisdom