#!/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"; } #### ./script.pl -w The outer key(user) is user1. The key(machine) is machine1: The key is machine1key4, the value is machine1value4. The key is machine1key1, the value is machine1value1. The key is machine1key2, the value is machine1value2. The key is machine1key3, the value is machine1value3. #### ./script.pl -f The outer key(user) is user1. The key(machine) is machine1: The key(machine_key) is machine1key4 Can't use string ("machine1value4") as a SCALAR ref while "strict refs" in use at ./script.pl line 50.