Personally I hate to see questions that are in fact FAQs or answered somewhere not too deep inside the docs, so I hope that this is not one such question. As a disclaimer I've checked
perlfaq, PM, CPAN and Google: I have found some info, but not a short, definitive answer.
I would like to write a script that supports both a cmd line UI and a GUI (Tk), and in addition to cmd-line switches to activate one or the other, I'd like to it automatically start in GUI mode if an X server is available on the machine it's being launched.
In particular I gave a peek into the documentation of Tk itself, but it's really huge, and at a first glance I could not find anything relevant.
Also, once I find an answer to my question, I was thinking of organizing my program along these lines:
#!/usr/bin/perl
use strict;
use warnings;
use File::Basename;
use FindBin qw/$Bin/;
my $name=basename $0;
# Code to detect X
exec $haveX ? "$Bin/$name.X" : "$Bin/$name.cmd";
__END__
Of course in that case I would put most of the non-UI code into a module and call it from the respective '.X' and '.cmd' versions. Does this sound as a good idea or would you do it differently?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.