Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

•Re: Reference problem?

by merlyn (Sage)
on Oct 07, 2003 at 16:52 UTC ( [id://297332]=note: print w/replies, xml ) Need Help??


in reply to Reference problem?

$volInfo->{volumes}{0}, $volInfo->{volumes}
Those both can't be user-defined data. The value at the key of volumes is either your data, or a hashref to more of your data, but not both. I bet if you add use strict, your program will stop working.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re: •Re: Reference problem?
by hotshot (Prior) on Oct 08, 2003 at 09:51 UTC
    As you said, I indeed expect to get in the volumes key a data or a hash ref (and not both). I had a bug in the program so I added the print lines, and then I got what I got, this is the source of my bug but I can't understand how I can get such a thing.
    The following is the full function (with debugs):
    sub readClusterVolumes { my %volumesInfo; print "checkpoint 1:\n", Dumper(\%volumesInfo); print "vol: ", $volumesInfo{volumes}, ', ', $volumesInfo{volumes}{ +0}, ', ', $volumesInfo{volumes}{1}, "\n"; my @volumesNodeIDs = &getParam($PARAMS_VOLUMES_NODE_LIST); # shou +ld return (0 1) or nothing dependin whether the parameter exists my (%volumes, $tmp, $volumeKey); $volumesInfo{maxVolId} = &getParam($PARAMS_MAX_VOLUME_ID); $volumesInfo{isInternal} = &getParam($PARAMS_INTERNAL_DISKS); for (my $i = 0; $i < @volumesNodeIDs; $i++) { print "in for loop\n"; ($volumeKey = $PARAMS_NODEX_VOLUMES) =~ s/X/$volumesNodeIDs[$i +]/; $tmp = &getCDBParam($volumeKey, $TRUE); if ($tmp && $tmp ne '') { print "in if, tmp :$tmp\n"; $volumes{$volumesNodeIDs[$i]} = $tmp; } } print "checkpoint 2:\n", Dumper(\%volumesInfo); print "vol: ", $volumesInfo{volumes}, ', ', $volumesInfo{volumes}{ +0}, ', ', $volumesInfo{volumes}{1}, "\n"; if (scalar(keys(%volumes)) == 0) { print "no voluems #######\n"; $volumesInfo{volumes} = 'none'; } else { print "voluems exist #######\n"; $volumesInfo{volumes} = \%volumes; } print "checkpoint 3:\n", Dumper(\%volumesInfo); print "vol: ", $volumesInfo{volumes}, ', ', $volumesInfo{volumes}{ +0}, ', ', $volumesInfo{volumes}{1}, "\n"; return \%volumesInfo; };
    I will also add that this happens in the second call to the function. in the first call the output is:
    checkpoint 1: $VAR1 = {}; vol: , , in for loop in if, tmp :0 1 2 3 4 in for loop in if, tmp :0 1 2 3 4 checkpoint 2: $VAR1 = { 'volumes' => {}, 'maxVolId' => '4', 'isInternal' => 'false' }; vol: HASH(0x8479e1c), , voluems exist ####### checkpoint 3: $VAR1 = { 'volumes' => { '1' => '0 1 2 3 4', '0' => '0 1 2 3 4' }, 'maxVolId' => '4', 'isInternal' => 'false' }; vol: HASH(0x88d8144), 0 1 2 3 4, 0 1 2 3 4
    and in the second call I get:
    checkpoint 1: $VAR1 = {}; Use of uninitialized value in print at /vobs/mng/exadmin/var/www/cgi-b +in/lib/clusterEdit.pl line 21, <SESS> line 60. Use of uninitialized value in print at /vobs/mng/exadmin/var/www/cgi-b +in/lib/clusterEdit.pl line 21, <SESS> line 60. Use of uninitialized value in print at /vobs/mng/exadmin/var/www/cgi-b +in/lib/clusterEdit.pl line 21, <SESS> line 60. vol: , , checkpoint 2: $VAR1 = { 'volumes' => {}, 'maxVolId' => 'none', 'isInternal' => 'false' }; vol: HASH(0x847a2c0), , no voluems ####### checkpoint 3: $VAR1 = { 'volumes' => 'none', 'maxVolId' => 'none', 'isInternal' => 'false' }; vol: none, 0 1 2 3 4, 0 1 2 3 4
    I removed some Unintialized value... warnings I got, so it will be more clearer. You can see that it somehow 'remembers' the old values from the first call (the last line of the second output). I can't understand how that can be.
    All I want under the volumes key is none where there are no volumes, and the volumes themselvs when volumes exist.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://297332]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (5)
As of 2024-04-19 13:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found