Hey Daniel,

It seems you change only a single hash value: the value at key $hashname:

$hash{$hashname}{'test1'}= "crud9";

Each hash within the major hash is independent (has its own storage.)

To do what you want, you would have to:

$hash{"Crud1'}{'test1'}= "crud9";
$hash{"Crud2'}{'test1'}= "crud9";
$hash{"Crud3'}{'test1'}= "crud9";

Or have some sort of loop.

Aloha - Beau.

PS: I have been converting my config files to XML (XML::Parser, etc.) Works
good!

-----Original Message-----
From: Daniel Falkenberg [mailto:[EMAIL PROTECTED]]
Sent: Thursday, October 25, 2001 6:51 PM
To: [EMAIL PROTECTED]
Subject: Chainging values in a hash..


Hey List,

I am working on a problem where I have a hash of a hash that need
updating and to be writen back into a text file.  At the moment the hash
looks like this...

%hash = (
             'Crud1' => {
                          'test1' => 'crud10',
                          'test2' => 'crud11'
                        },
             'Crud2' => {
                           'test1' => 'crud10',
                           'test2' => 'crud11'

                         },
             'Crud3' => {
                            'test1' => 'crud10',
                            'test2' => 'crud11'
                          }
           );

Is it possible to change all the values of crud10 to crud9.  At the
moment my code looks like this...

read_config(); #create hash like above. At the moment it works fine
#change variable of crud10 to crud 9...
$hash{$hashname}{'test1'}= "crud9";
write_config($tunnelfile, %tunnels);
#Write config looks like this...

sub write_config {
    open FILE, ">$tunnelfile" or die "cannot open $tunnelfile: $!\n";
    for $t (keys %hash) {
        print $t, "\t\n\n";;
        print FILE "[$t]\n";
        print FILE "$_=$hash{$t}{$_}\n" for keys %{$tunnels{$t}};
    }
    close(FILE)               or die "Closing: $!";
}

But for some reason write_config will only change %Crud3 ( 'test1' =>
'crud9'); ...

and nothing else.  Am I missing something major here?

Kind regards,

Dan

==============================
VINTEK CONSULTING PTY LTD
(ACN 088 825 209)
Email:  [EMAIL PROTECTED]
WWW:    http://www.vintek.net
Tel:    (08) 8523 5035
Fax:    (08) 8523 2104
Snail:  P.O. Box 312
        Gawler   SA   5118
==============================


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to