I can confirm the bug. It sometimes manifests even with just 2 existing styles. Adding a MainLoop also shows that the styles are overwriting each other, i.e. the items have wrong colours.

A full example rewritten to use strict to rule out typos in variable names, plus shortened according to the DRY principle.

#!/usr/bin/perl use strict; use warnings; use Tk; use Tk::ItemStyle; use Tk::TList; my $mw = Tk::MainWindow->new(); my $tl = $mw->TList->pack; my %TkStyle; my %count; for my $color (qw( Black Red Green Blue )) { $TkStyle{$color} = $mw->ItemStyle('text', -stylename => $color, -foreground => $color, -background => 'Wheat', -selectforeground => 'LightSeaGr +een'); $tl->insert('end', -itemtype => 'text', -text => $color, -style => $TkStyle{$color}); ++$count{ $TkStyle{$color} }; } for my $colour (keys %TkStyle ) { my $style = $TkStyle{$colour}; printf("%10s has count %d (style=$style)\n", $colour, $count{$styl +e}); } MainLoop();

Update: The large Tk application I maintain at work uses ItemStyle, but I've never encountered the bug. I checked the code and it seems the only difference is our application doesn't set the -stylename: And indeed, after commenting out the -stylename line, the hashes are always unique!

Update 2: Reported.

map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]

In reply to Re: ItemStyle not returning a unique hash (Updated) by choroba
in thread 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.