in reply to How to use a module without installing it?

Is there a way to just cut/paste the module's code inside of my Perl code? ... I'd love to see an example.
Yes. Here is a trivial example:
Foo::bar(); package Foo; sub bar {print "bar: hello\n"}

Replies are listed 'Best First'.
Re^2: How to use a module without installing it?
by almut (Canon) on Aug 03, 2009 at 22:58 UTC

    In the more general case, it's usually a good idea to put an extra block (pair of curlies) around each included module's code section. This is in order to emulate the extra scope implied when having the code in a separate file. I.e.

    ... { package Foo; sub bar {print "bar: hello\n"} } { package Bar; ... }

    Of course, it won't make a difference in this simple case, but with more complex code, subtle bugs due to scoping issues might result without the extra braces.

    Also, depending on whether the included code needs to be compiled/run prior to the rest of the script (as a normal use would do), you might need to put the code in a BEGIN {} block...

      Hi,

      I tried your technique for the module I needed - let's call it "A::B".
      I pasted the A::B module above my code, inside curly braces {}
      The "A::B" code "require"s the parent code "A", which I pasted above it, inside curly braces {}
      and the "A" code "require"s code "A::C", which I pasted above it, inside curly braces {}

      Now I get the error message:

      Can't locate A/C.pm in @INC

      Any ideas?

        If I'm understanding you correctly, you still have a require (or use) in your code — at least that's what the error message "Can't locate..." would suggest.

        Once you have a module's code pasted into the main script, there's no longer any need to require it (i.e. load it from an external file), as it's already there... So just remove or comment out the respective require/use instructions.