Please post a complete working example that we can run. Make up arrays for the demo like q(a..z). From first glance, it appears you are trying to build variable names, when you should be using hash or an array. See how bad it is to use a variable as a variable name

From a google search:

#!/usr/bin/perl use warnings; use strict; my $part_2 = "Not a good idea"; my $var1 = "part"; my $var2 = "2"; my $compound = eval "\$${var1}_$var2"; print "$compound\n"; __END__ There are three important things to note about this: 1. it is a really bad idea 2. the first $ must be escaped to avoid the first evaluation (the interpolation into the string) 3. $var1 must be in the form of ${var1} because $var1_ is a valid vari +able name
Post a complete minimal example, and we will show you how to use a hash instead. You can make a reference like \$hash{$name} Or if you prefer, arrays can be used like in the following.
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::Pane; use Encode; my $topdir= shift || '.'; my @subdirs = get_sub_dirs($topdir); my $mw = tkinit(); $mw->geometry('400x400+100+100'); my $sp = $mw->Scrolled('Pane', -scrollbars=>'osoe', sticky=>'nwse') ->pack(-expand=>1, -fill=>'both' ); my @cbvalues; my @cbnames; my $count = 0; foreach my $d( @subdirs){ $cbnames[$count] = $d; $sp->Checkbutton(-text => $d, -font=>[arial => 12], -onvalue => 1, -offvalue => 0, -variable => \$cbvalues[$count], -font => 'big', -bg => 'white', )->pack(-anchor=>'w')->pack(); $count++; } my $showbutton= $mw->Button(-text=>'Show Selected', -bg => 'lightyellow', -command => sub{ my @selected = (); foreach my $c( 0.. $count ){ if ( $cbvalues[$c] ){ push @selected, $cbnames[$c]; } } print "@selected\n"; } )->pack(); MainLoop(); sub get_sub_dirs { my $dir = shift; opendir my $dh, $dir or die "Error: $!"; my @files = grep !/^\.\.?$/, readdir $dh; @files = map { decode( 'utf8', "$dir/".$_ ) } sort @files; closedir $dh; my @sdirs; for my $file ( @files ) { if(-d $file){push @sdirs,$file;} } return @sdirs; }

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

In reply to Re: Perl/Tk - Dynamic Checkbuttons? by zentara
in thread Perl/Tk - Dynamic Checkbuttons? by Monkless

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.