#!/usr/bin/perl #==================================================== # Test script for HoHoH. To run: # ./script -a to build the db file. # ./script -w to print with while loop. # ./script -f to print with for loop(partially fails). #==================================================== use strict; use warnings; use DBM::Deep; use Getopt::Long; my ( $add, $while_print, $for_print ); GetOptions( "add" => \$add, "while_print" => \$while_print, "for_print" => \$for_print ); my $user = 'user1'; my $machine = 'machine1'; if ($add) { my $db = DBM::Deep->new("foo_pm.db"); $db->{$user} = { $machine => { $machine . key1 => "$machine" . 'value1', $machine . key2 => "$machine" . 'value2', $machine . key3 => "$machine" . 'value3', $machine . key4 => "$machine" . 'value4' }, }; } if ($while_print) { my $db = DBM::Deep->new("foo_pm.db"); while ( my ( $outerkey, $value_user ) = each %$db ) { print "The outer key(user) is $outerkey. \n"; while ( my ( $key2, $value_machine ) = each %{ $db->{$outerkey} } ) { print " The key(machine) is $key2: \n"; while ( my ( $key3, $value ) = each %{ $db->{$outerkey}->{$key2} } ) { print " The key is $key3, the value is $value.\n"; } } } print "\n"; } if ($for_print) { my $db = DBM::Deep->new("foo_pm.db"); while ( my ( $outerkey, $value_user ) = each %$db ) { print "The outer key(user) is $outerkey. \n"; while ( my ( $key2, $value_machine ) = each %{ $db->{$outerkey} } ) { print " The key(machine) is $key2: \n"; for my $key3 ( keys %{ $db->{$outerkey}->{$key2} } ) { print " The key(machine_key) is $key3\n"; my $value_param = ${ $db->{$outerkey}->{$key2}{$key3} }; print " The value is $value_param\n"; } } } print "\n"; }