Re: subroutines vs method vs function



BH <Benson.Hoi@xxxxxxxxxxxxxx> writes:

Hi,

Can someone clarify the 3 terms wrt Perl providing with some examples?

they're all subroutines. functions and subroutines are the same thing in
perl.

methods are subroutines that are called using method resolution and get
the object passed as the first argument. IOW there methods as such, just
functions that get called using method call semantics.

package Bla;
sub something { print "my arguments are '@_'\n" }

Bla->something(); # call as (class) method

something(); # call as function

Bla::something(); # call as function with explicit package name

my $o = bless {},"Bla"; # make a "Bla" object
$o->something(); # call as object method

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
.