andy4321 has asked for the wisdom of the Perl Monks concerning the following question:
I've noticed that I'm getting inconsistent colours (colors).
I've tracked this down to ItemStyle returning inconsistent hashes (in reality, references to hashes).
Inconsistent in that:
The code below amply demonstrates the problem:
There's no MainLoop ... just so that the program exits immediately.#!/usr/bin/perl use Tk; use Tk::ItemStyle; $mw = Tk::MainWindow->new(); $TkStyle{Black } = $mw -> ItemStyle("text", -stylename=>"Black", + -foreground=>"Black", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{LightGrey } = $mw -> ItemStyle("text", -stylename=>"LightGrey +", -foreground=>"grey60", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{Red } = $mw -> ItemStyle("text", -stylename=>"Red", + -foreground=>"Red", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{Blue } = $mw -> ItemStyle("text", -stylename=>"Blue", + -foreground=>"Blue", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{RoyalBlue1} = $mw -> ItemStyle("text", -stylename=>"RoyalBlue +1", -foreground=>"RoyalBlue1", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{RoyalBlue3} = $mw -> ItemStyle("text", -stylename=>"RoyalBlue +3", -foreground=>"RoyalBlue3", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{Green } = $mw -> ItemStyle("text", -stylename=>"Green", + -foreground=>"ForestGreen", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); $TkStyle{Orange } = $mw -> ItemStyle("text", -stylename=>"Orange", + -foreground=>"Orange", -background=>"Wheat", -selectforegrou +nd=>"LightSeaGreen"); foreach $colour (keys %TkStyle) { $style = $TkStyle{$colour}; $count{$style}++; } foreach $colour (keys %TkStyle ) { $style = $TkStyle{$colour}; printf("%10s has count %d (style=$style)\n", $colour, $count{$sty +le}); }
A typical output may be:
RoyalBlue3 has count 3 (style=Tk::ItemStyle=HASH(0x556aa72eb408))
Orange has count 1 (style=Tk::ItemStyle=HASH(0x556aa72eb4b0))
RoyalBlue1 has count 1 (style=Tk::ItemStyle=HASH(0x556aa72e61d0))
Red has count 3 (style=Tk::ItemStyle=HASH(0x556aa72eb408))
Blue has count 3 (style=Tk::ItemStyle=HASH(0x556aa72eb408))
Green has count 2 (style=Tk::ItemStyle=HASH(0x556aa72e6128))
LightGrey has count 1 (style=Tk::ItemStyle=HASH(0x556aa72e6188))
Black has count 2 (style=Tk::ItemStyle=HASH(0x556aa72e6128))
This does seem very curious and ... wrong?
Running the script can return very different failure signatures.
Occasionally, all the references to hashes are unique ... but that seems to be more the exception than the norm.
I have added a loop (not shown) to the creation of the ItemStyle's ... so that duplicated hashes are deleted and new ones created.
Sometimes, I have to iterate 3 or even 4 times until I get a completely unique set of hashes.
Any thoughts?
Andrew
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: ItemStyle not returning a unique hash (Updated)
by choroba (Cardinal) on Apr 08, 2025 at 09:34 UTC | |
by andy4321 (Novice) on Apr 08, 2025 at 11:21 UTC |