CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Laurent_R] create a dbm with a hash, that has a key, with 2 values: Edit Log



dunsta
Novice

May 20, 2013, 3:26 AM


Views: 304
Re: [Laurent_R] create a dbm with a hash, that has a key, with 2 values

Hi and Thanks for the reply.

I am trying to use DBM to create a hash that looks like the VAR in my example.
But when I create it like this:


Code
my(%mailList2, $name, $email, $group); 

dbmopen(%mailList2, "mailingLists2",0644) || die "Cannot open DBM: $!";

print "Enter a number: ";
chomp($group=<STDIN>);
print "Enter a name: ";
chomp($name = <STDIN>);
print "Enter an email: ";
chomp($email = <STDIN>);

$mailList2{$group}{$name} = $email;


and try to access the data like this


Code
for my $group (keys %mailList2) { 

for my $name (keys %{$mailList2{$group}}) {

print $group, " -> ", $name, " -> ", $mailList2{$group}{$name}, "\n";

}

}


The output is only the input from the latest run, the data does not seem to be persisting.


(This post was edited by dunsta on May 20, 2013, 4:30 AM)


Edit Log:
Post edited by dunsta (Novice) on May 20, 2013, 4:30 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives