As has been pointed out, using the arrow operator passes the class name (or object instance, if you have one) as the first argument to the method. However, you may not want to dive into OO Perl just yet. In that case, call the subroutine as a function, not as a method. That means that you change the '->' to '::'.

use Foo; my $name = Foo::test("TEST"); print "Name: $name\n";

Once you get that down, you can start learning about Exporter and learn to export the selected functions you need:

package Foo; use strict; use warnings; use base 'Exporter'; our @EXPORT_OK = ( 'test' ); sub test { my $thing = shift; return $thing; }

With that code anything that can be accessed through your package (such as package variables and subroutines) can be exported to your class by listing the item in your "import list":

use Foo qw(test); my $name = test("TEST"); print "Name: $name\n";

See the documentation for Exporter for more information. Have fun!

Cheers,
Ovid

New address of my CGI Course.


In reply to Re: First Perl Module!! by Ovid
in thread First Perl Module!! by Anonymous Monk

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.