crusty_collins has asked for the wisdom of the Perl Monks concerning the following question:
Obviously this is not going to work correctly. The real problem is getting a hash that looks like this $hash{rvd}{RTD}{daemonPort} => 7500; without knowing how deep I am going to go. Any ideas out there?while( <FILE> ) { @tmp = split(/\*/); SWITCH: { for ($i = 0; $i <= $#tmp; $i++) { if ($tmp[$i]) { # make sure the first value is the key. print "Setting key : $KEY\n", if ($Verbose); $KEY = "$tmp[$i]"; # populate the key with the other values # hostname*rvd*daemonPort : 7500 for ($i; $i <= $#tmp; $i++) { # reached the last var populate the va +lue if ( $tmp[$i] =~ /^(\w+)\s+\:\s+([A-Z. +0-9_\/])/ig) { $Vars{$KEY}{$tmp[$i - 1]}{$1} => $2; print "$tmp[$i]"; }else{ $Vars{$KEY}{$tmp[$i]}; } } last SWITCH; } } } } # while <file>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Parse file to Hash of Hash etc.
by mrborisguy (Hermit) on May 18, 2005 at 18:08 UTC | |
by merlyn (Sage) on May 18, 2005 at 19:02 UTC | |
by mrborisguy (Hermit) on May 18, 2005 at 19:23 UTC | |
by merlyn (Sage) on May 18, 2005 at 19:25 UTC | |
by crusty_collins (Friar) on May 18, 2005 at 19:41 UTC | |
by merlyn (Sage) on May 18, 2005 at 20:14 UTC | |
by crusty_collins (Friar) on May 18, 2005 at 20:15 UTC | |
by crusty_collins (Friar) on May 18, 2005 at 18:44 UTC | |
by mrborisguy (Hermit) on May 18, 2005 at 19:01 UTC | |
by crusty_collins (Friar) on May 18, 2005 at 18:48 UTC |