Here's an example taken from Maplat::Web::MemCache.pm:

my $memd; my $memd_loaded = 0; # Decide which Memcached module we want to use # First, we try the festest one, then the standard # one and if everything fails we use our own my $memdtype; { ## no critic (BuiltinFunctions::ProhibitStringyEval) if(eval('require Cache::Memcached::Fast')) { print " Cache::Memcached::Fast available.\n"; $memdtype = "Cache::Memcached::Fast"; $memd = Cache::Memcached::Fast->new ({ servers => [ $self->{service} ], namespace => $self->{namespace} . "::", connect_timeout => 0, }); $memd_loaded = 1; $self->{mctype} = "fast"; } elsif(eval('require Cache::Memcached')) { print " No Cache::Memcached::Fast ... falling back to C +ache::Memcached\n"; $memdtype = "Cache::Memcached"; $memd = Cache::Memcached->new ({ servers => [ $self->{service} ], namespace => $self->{namespace} . "::", connect_timeout => 0, }); $memd_loaded = 1; $self->{mctype} = "slow"; } else { print " No Cache::Memcached* available ... will try to +use Maplat::Helpers::Cache::Memcached\n"; } }
This just looks up which Memcached modules are available and tries to load one of those.

Don't use '#ff0000':
use Acme::AutoColor; my $redcolor = RED();
All colors subject to change without notice.

In reply to Re: Best way to dynamically use a .pm? by cavac
in thread Best way to dynamically use a .pm? by TJPride

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.