There's no difference in declaring a method and a subroutine. The only difference is how you call methods and what arguments they get.
sub some_function
{
my ($first, $second) = @_;
...
}
sub some_method
{
my ($self, $first, $second) = @_;
...
}
You need to call a method with a class name or an object:
SomeClass->some_method( $first, $second );
$some_object->some_method( $first, $second );
To create an object, call a constructor (a method called with a class name). A constructor uses the bless operator to associate a reference with a class name:
package SomeClass;
sub new
{
my $class = shift;
bless {}, $class;
}
...
my $some_object = SomeClass->new();
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.