Based on your first sentence, I would opt to go another route.

One thought would be to write your own module(s) that require other modules and provide instructions for your users on how to properly install the needed modules for your code to work. But then you have the challenge of being tech support to help debug installation issues. And both this route and what you have attempted are depending on internet access to be able to download and install needed modules.

The approach that I would take would be to use the pp utility from PAR::Packer to bundle the code into a stand alone executable and then distribute the executable. This eliminates the need to provide support to modify/maintain the proper Perl environment on your users' systems.

(NOTE: This recommendation is not about making the code run faster or obfuscating the source code. The motivation is to simplify support and maintenance - i.e. maintain a Perl development environment on an OS similar to what end users will use and just provide the stand alone executable.)


In reply to Re: Installing CPAN Modules within BEGIN of PERL Script by dasgar
in thread Installing CPAN Modules within BEGIN of PERL Script by GhostCode

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.