Hi everyone, here's a simple but annoying problem: I'm trying to use Tk in a multiplatform script. The windows version is packed into a self-contained .exe with PAR::Packer, so on Windows, I can pack in Tk and it works out of the box for the user. On other platforms, I want the script to be able to run without installing Tk.

Now, based on a previous thread, I'm using use if $^O eq "MSWin32", "Tk"; to load Tk conditionally. So far, so good, but of course the code later on contains the compulsory MainLoop; line. This causes a problem on *nix, as I get an error about the Bareword "MainLoop". Understandable, as "MainLoop;" makes no sense to the perl compiler in the absence of the module. if ($gui eq "on") {MainLoop} doesn't help of course, because the error is thrown at compile time. I could just switch off strict subs and warnings and the script would run fine, but that's not very elegant, is it?
So, is there an easy way to run the script with strict and warnings on?

In reply to Troubles when trying to use Tk conditionally by Anonymous Monk

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.