HoH deletion problem after 5.6.1 to 5.8.4 upgrade

W

woodenbicycle

Help! I am just a perl tinkerer who doesn't know much about data
strctures. I am having a problem with a little pet project of mine.
Please take a look and help me if you have time.

I upgraded from 5.6.1 to 5.8.4 and now some of my old code now seems to
be broken. I have been banging my head over this over the weekend and I
think the problem has to do with the way I am deleting an item from my
Hash of Hashes.

I have the code segment below. "HoH" is the Hash of Hashes. "key_list"
is a list of the keys in HoH. "selected" is the index number of the
item I wish to delete from the HoH via the key_list.

0-50: ### Obtain $selected by a Perl/Tk scrolled listbox and button
51: print "running...\n";
52: my $key = $key_list[$selected];
53: print "delete item# $key\n";
54: delete $HoH{$key};
55: $key_list[$selected] = '0';
56+: ### Build new key_list with a simple loop

I get the following to the console when code is run:
running...
delete list# ARRAY(0x85089a8)
Use of reference "ARRAY(0x85089a8)" as array index at testcase.pl line
52.
Use of uninitialized value in concatenation (.) or string at
testcase.pl line 53.
delete item#
Use of uninitialized value in delete at testcase.pl line 54.
Use of reference "ARRAY(0x85089a8)" as array index at testcase.pl line
55.
Out of memory!
Callback called exit.
Callback called exit.
Segmentation fault

This code seems to work fine under 5.6.1 but does not work under 5.8.4.
I thank you now for your help!

Pepper
 
X

xhoster

Help! I am just a perl tinkerer who doesn't know much about data
strctures. I am having a problem with a little pet project of mine.
Please take a look and help me if you have time.

I upgraded from 5.6.1 to 5.8.4 and now some of my old code now seems to
be broken. I have been banging my head over this over the weekend and I
think the problem has to do with the way I am deleting an item from my
Hash of Hashes.

I don't think that that is your problem. The problem is probably
earlier (when $selected is getting set to an arrayref rather than an
integer) or later (When you run out of memory and die, apparently
in a part of the code you don't show.)

I have the code segment below. "HoH" is the Hash of Hashes. "key_list"
is a list of the keys in HoH. "selected" is the index number of the
item I wish to delete from the HoH via the key_list.

No, it isn't. Acccording the output generated by line 53, $selected
is ARRAY(0x85089a8).
0-50: ### Obtain $selected by a Perl/Tk scrolled listbox and button
51: print "running...\n";
52: my $key = $key_list[$selected];
53: print "delete item# $key\n";
54: delete $HoH{$key};
55: $key_list[$selected] = '0';
56+: ### Build new key_list with a simple loop

I get the following to the console when code is run:

What did you get as output back under 5.6.1 when the code
was working?
running...
delete list# ARRAY(0x85089a8)
Use of reference "ARRAY(0x85089a8)" as array index at testcase.pl line
52.

Looks like GIGO to me. Figure out why the garbage is getting in.

Xho
 
W

woodenbicycle

I obtain $selected on line 50, which looks like this:
50: my $selected = $viewlist->curselection;

"viewlist" is my scrolled listbox (Perl/Tk) which I define and fill
like this:
37: $viewlist = $viewframe->Scrolled("Listbox", -scrollbars => 'e',
-width => 32, -height => 5, -selectmode => 'single')->pack(-side =>
'top');
38: $viewlist->insert('end', "Item 0");
39: $viewlist->insert('end', "Item 1");

I added a line right below line 50 to ouput the value of $selected the
moment it is obtained:
51: print "$selected\n";

With Perl 5.6.1 running the Tk module 800.024 (Debian Woody Stable),
the output of that line is the integer "1"

With Perl 5.8.4 running the Tk module 800.025 (Debian Sarge Testing),
the output of that line is the array reference show in the output in my
initial post.

I'm baffled and will rephrase my question and post it in
comp.lang.perl.tk.

Pepper
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,533
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top