Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I usually create my own module prefix -- named after the project or the place I worked. For example, you might put everything under Mu with modules named like <code>Mu::Foo</code> and <code>Mu::Bar</code>. Use multiple modules (don't try to keep everything in one single file) and name your modules with the <code>*.pm</code> suffix.</p> <p>Then, if the <code>Mu</code> directory is in the same directory as your programs, you only need to do this:</p> <pre><code>use Mu::Foo; use Mu::Bar; </code></pre> <p>If they're in another directory, you can do this:</p> <pre><code>use lib qw(/path/to/other/directory); use Mu::Foo; use Mu::Bar; </code></pre> <blockquote> <p>Is it possible at all including pm files in pm files?</p> </blockquote> <p>Why certainly yes.</p> <blockquote> <p>So, I want to create files in some kind of directory structure which I can include. I want the files that I include will be <strong>exaclty like if the text were written in the file where I do the include.</strong></p> </blockquote> <p>That's a bad, bad idea. You are better off using the package mechanism. That is, declare each of your module as a separate package name. Otherwise, your module will have a variable or function in it that your script will override, and you'll never, ever know it.</p> <p>In Perl, you can reference variables in your modules by prefixing it with the module name. (Such as <a href="http://perldoc.perl.org/File/Find.html" rel="nofollow">File::Find</a> does. For example <code>$File::Find::Name</code> is the found file's name. This doesn't pollute your namespace.</p> <p>If you really want your module's functions and variables in your namespace, look at the <a href="http://perldoc.perl.org/Exporter.html" rel="nofollow">@EXPORT_OK</a> list variable in <a href="http://perldoc.perl.org/Exporter.html" rel="nofollow">Exporter</a>. This is a list of all the variables and functions that you'd like to import into your module's namespace. However, it's not automatic, you have to list them next to your <code>use</code> statement. That way, you're more likely to know about them. Using Exporter isn't too difficult. In your module, you'd put:</p> <pre><code>package Mu::Foo; use Exporter qw(import); our EXPORT_OK = qw(convert $fundge @ribitz); </code></pre> <p>Then, in your program, you'd put:</p> <pre><code>use Mu::Foo qw(convert $fundge @ribitz); </code></pre> <p>Now you can access <code>convert</code>, <code>$fundge</code> and <code>@ribitz</code> as if they were part of your main program. However, you now have documented that you're pulling in these subroutines and variables from <code>Mu::Foo</code>. </p> <p><em>(If you think this is complex, be glad I didn't tell you that you really should use Object Oriented methods in your Modules. That's really the best way to do it.)</em></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload