I wrote the following bit of code using Tk:
use strict; use Win32::Clipboard; use Tk; my $change_mode = \&change_mode; my $mode = 0; my $clip = Win32::Clipboard(); my $main = new MainWindow; $main->Label(-text => 'Clipboard Case Changer' )->pack; $main->Button(-text => 'On/Off Toggle', -command => $change_mode )->pack; MainLoop; sub change_mode { $mode = !$mode; } #Change clipboard contents to uppercase, if $mode == 1; while(1) { $clip->WaitForChange(); my $contents = $clip->Get(); if ($mode) { $clip->Set(uc($contents)); } }
Even though I'm new to Tk, I was pretty sure the above code wouldn't work. Sure enough, it doesn't. I'm guessing it's because the infinite loop, outside of the 'MainLoop,' never gets executed. So am I going to need a thread here? I've dabbled with threads in Java. But I'm not familiar with threading at all with Perl and I hear it's kind of a nightmare. Is there a more obvious technique I could be using that I'm missing?

$PM = "Perl Monk's";
$MCF = "Most Clueless Friar Abbot Bishop Pontiff";
$nysus = $PM . $MCF;
Click here if you love Perl Monks


In reply to Does this Tk program require a thread? by nysus

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.