Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: using 'use' conditionally

by dash2 (Hermit)
on Nov 06, 2002 at 17:31 UTC ( [id://210812]=note: print w/replies, xml ) Need Help??


in reply to using 'use' conditionally

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~

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://210812]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (2)
As of 2024-04-25 18:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found