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:

#!/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}); }
There's no MainLoop ... just so that the program exits immediately.

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

In reply to ItemStyle not returning a unique hash by andy4321

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.