You cannot do use Module and assume it to have only lexical effects. use is handled at compile time. You can do what you want at run time though, by using require. Something like:
if ($arg is a FILEHANDLE) { require DBI::Pretty::File; %hash = DBI::Pretty::File::read_stuff_from_file ($arg); } elsif ($arg is a XML datastream) { require DBI::Pretty::XML; %hash = DBI::Pretty::XML::read_stuff_from_xml ($arg); }

I do get the feeling you are mixing OOP with procedurial coding and getting the worst of two worlds. I would either make $arg an object so I could do $arg -> read_stuff, or I'd make a function, possible in a separate file (and module), so that I could do %hash = read_stuff ($arg) and put all the reading stuff from DBI::Pretty::File and DBI::Pretty::XML and other modules in there.

-- Abigail


In reply to Re: Scope of a Module? by Abigail
in thread Scope of a Module? by Masem

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.