Lots of people have pointed out BEGIN, "use if" and "require".
Another point is that (unless your program is very simple) you probably don't want to include the Tk interface and the command line interface in the same packages.
Instead do something like this:
my $iface = $opt_g ? new MyInterface::Tk : new MyInterface::CommandLin
+e;
The two MyInterface subclasses provide different ways of doing the same thing... so then you can write:
$iface->notify("Your flies are down");
$iface->ask("Do you want to zip them up?", 'Y', 'N');
This separates your interface code nice and cleanly from the rest of your program.
Of course, you still have to be careful what you require, because if Tk isn't installed, then MyInterface::Tk will presumably die on compilation.
dave hj~
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.