Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > conditional modules

Reply
Thread Tools

conditional modules

 
 
John
Guest
Posts: n/a
 
      08-06-2009
Hi

Can you access modules with a condition, ie

my ($language,$text);
if ($language eq 'English') {use English; $text=new English;}
elsif ($language eq 'German') {use German; $text=new German;}
etc

or is this preferable

use Language qw(english};

I don't want to load all languages when I am going to use only one.

Regards
John




 
Reply With Quote
 
 
 
 
smallpond
Guest
Posts: n/a
 
      08-06-2009
On Aug 6, 12:03*pm, "John" <(E-Mail Removed)> wrote:
> Hi
>
> Can you access modules with a condition, ie
>
> my ($language,$text);
> if ($language eq 'English') {use English; $text=new English;}
> elsif ($language eq 'German') {use German; $text=new German;}
> etc
>
> or is this preferable
>
> use Language qw(english};
>
> I don't want to load all languages when I am going to use only one.




=== foo ===
$pkg = shift;
eval "use $pkg";
MainWindow->new();
MainLoop();

perl foo Tk

This brought up a Tk window so I guess runtime
package binding is fine.

You need to eval the use statement that you want to
do to avoid having all of your packages loaded at
compile time.
 
Reply With Quote
 
 
 
 
Petr Vileta \fidokomik\
Guest
Posts: n/a
 
      08-06-2009
John wrote:
> Hi
>
> Can you access modules with a condition, ie
>
> my ($language,$text);
> if ($language eq 'English') {use English; $text=new English;}
> elsif ($language eq 'German') {use German; $text=new German;}
> etc
>


my ($language,$text);
if ($language eq 'English') {require English; $text=new English;}
elsif ($language eq 'German') {require German; $text=new German;}

--
Petr Vileta, Czech Republic
(My server rejects all messages from Yahoo and Hotmail.
Send me your mail from another non-spammer site please.)
Please reply to <petr AT practisoft DOT cz>

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      08-08-2009

Thank you, gentlemen, that was very useful.

Regards
John



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Modules setting values to nil in unprocessed conditional blocks? Nate Ruby 3 08-24-2009 06:48 PM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Importing modules from within other modules Tobiah Python 2 09-14-2003 09:18 PM
imputils - import problem modules from sys.modules Remy Cool Python 1 08-27-2003 02:25 PM



Advertisments