conditional modules

Discussion in 'Perl Misc' started by John, Aug 6, 2009.

  1. John

    John Guest

    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
    John, Aug 6, 2009
    #1
    1. Advertising

  2. John

    smallpond Guest

    Re: conditional modules

    On Aug 6, 12:03 pm, "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
    >
    > 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.
    smallpond, Aug 6, 2009
    #2
    1. Advertising

  3. 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>
    Petr Vileta \fidokomik\, Aug 7, 2009
    #3
  4. John

    John Guest

    Thank you, gentlemen, that was very useful.

    Regards
    John
    John, Aug 8, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alec S.
    Replies:
    10
    Views:
    10,142
    Alec S.
    Apr 16, 2005
  2. Remy Cool
    Replies:
    1
    Views:
    429
    Remy Cool
    Aug 27, 2003
  3. Tobiah
    Replies:
    2
    Views:
    310
    Tobiah
    Sep 14, 2003
  4. Ben Weintraub

    Disabling modules using Modules/Setup

    Ben Weintraub, Sep 9, 2006, in forum: Python
    Replies:
    0
    Views:
    351
    Ben Weintraub
    Sep 9, 2006
  5. Nate
    Replies:
    3
    Views:
    118
    n8agrin
    Aug 24, 2009
Loading...

Share This Page