Hi, I'm in the process of getting more familiar with writing modules since they pretty much rule. This subject has been a mystery to me for a long time until I actually took the time to read through the O'Reilly section of "Programming Perl" on Packages, Modules and Objects. Now it seems rather easily tackled.

However, there's something I'm still confused on here. So when you 'use Module qw(LIST)' it's like saying:

     BEGIN {
        require Module;
        Module->import(LIST);
     }
That much I understand. From what I understand about the -> operator, saying Module->import(LIST) is the same as saying &{$Module{import}}(LIST) correct? I also notice that there's no '$' on the front of Module so what is this symbol? I'm totally confused on this issue.

The thing that I did in learning the magic of modules, is build a very simple module like the following:

     package PerlModuleEducation1;
     use strict;
     use vars qw($someVar);
     
     sub import(@) {
        print "PerlModuleEducation1::import(\@) called.\n";
     }
     $someVar = 10;
     sub someFunc($$) {
        my ($s1,$s2) = @_;
        print "You called PerlModuleEducation1::someFunc($s1,$s2)!\n";
     }
Thus, if I use require then I can use $someVar and someFunc($$) with qualifiers. Also, if I use 'use' I can do virtually the same thing, but since the function has a prototype and use is really a BEGIN then I can use someFunc LIST. But the point being that I can use with out an error saying I have no import(LIST) function.

I originally thought that I'd have to create some anonymous hash called PerlModuleEducation1 and then put a refrence to a sub called 'import' inside it, but turns out, I can just write import as a normal function inside the .pm file and everything works fine. Why is that?

This has been R A D...


In reply to Perl Module Education by radman

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.