BEGIN { my $p_id_hash = { }; sub my_create { my ($w, $thing, $pparams) = @_; my $id = $w->$thing(@$pparams); my $pinfo = caller_info(); $p_id_hash->{$id} = [ $thing, @$pinfo ]; return $id; } sub caller_info { my $ln = (caller(1))[2]; my $sub = (caller(2))[3]; return [ $ln, $sub ]; } sub my_delete { my ($w, $id) = @_; my $pinfo = $p_id_hash->{$id} || 0; if (!$pinfo) { error_msg("Attempt to delete ID '$id' twice!"); } else { $w->delete($id); delete $p_id_hash->{$id}; return $id; } } sub show_id_hash { my @keys = sort keys %$p_id_hash; my $total = @keys; print "=" x 79, "\n"; for (my $i = 0; $i < $total; $i++) { my $key = $keys[$i]; my $pval = $p_id_hash->{$key}; my ($thing, $ln, $sub) = @$pval; printf "%3d. %16.16s -- %s[%4d]\n", $i+1, $thing, $sub, $ln; } print "Total keys = $total\n"; print "=" x 79, "\n"; } } #### my $id = $canvas->createRectangle(@opts); ... $canvas->delete($id); #### my $id = my_create($canvas, "createRectangle", [ @opts ]); ... my_delete($canvas, $id); #### ... 32. createText -- main::draw_coordinates[ 936] 33. createText -- main::draw_coordinates[ 936] 34. createText -- main::draw_coordinates[ 936] 35. createText -- main::draw_coordinates[ 936] 36. createText -- main::draw_coordinates[ 936] 37. createText -- main::draw_coordinates[ 936] 38. createText -- main::draw_coordinates[ 936] 39. createText -- main::draw_coordinates[ 936] 40. createText -- main::draw_coordinates[ 936] 41. createText -- main::draw_coordinates[ 936] 42. createText -- main::draw_coordinates[ 936] ... #### sub draw_coordinates { my ($pboard) = @_; # Delete existing coordinate text my $canvas = $pboard->{'canvas'}; my $ptext = $pboard->{'text'}; map { my_delete($canvas, $_) } @$ptext; $pboard->{'text'} = [ ]; for (my $i = 0; $i < $ncols; $i++) { my $x = $borderx + $i * $cellx + $i * $linex + $linex / 2; for (my $j = 0; $j < $nrows; $j++) { my $y = $bordery + $j * $celly + $j * $liney + $liney / 2; my @opts = ($x, $y, -text => coor_to_square([$i, $j])); push @opts, -anchor => 'nw'; ($coor_font || 0) and push @opts, -font => $coor_font; my $id = my_create($canvas, "createText", [@opts]); push @$ptext, $id; } } } #### my $ptext = $pboard->{'text'}; #### map { my_delete($canvas, $_) } @$ptext; #### $pboard->{'text'} = [ ]; #### ... my $id = my_create($canvas, "createText", [@opts]); push @$ptext, $id; #### $pboard->{'text'} = [ ]; #### ... my $id = my_create($canvas, "createText", [@opts]); push @$ptext, $id; #### $ptext = $pboard->{'text'} = [ ]; #### @$ptext = ( ); # Instead of $pboard->{'text'} = [ ];