Re: subroutines vs method vs function
- From: Joost Diepenmaat <joost@xxxxxxxxx>
- Date: Wed, 27 Feb 2008 23:57:45 +0100
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/
.
- Follow-Ups:
- Re: subroutines vs method vs function
- From: Joost Diepenmaat
- Re: subroutines vs method vs function
- References:
- subroutines vs method vs function
- From: BH
- subroutines vs method vs function
- Prev by Date: Re: parameterized sorting function
- Next by Date: Re: subroutines vs method vs function
- Previous by thread: subroutines vs method vs function
- Next by thread: Re: subroutines vs method vs function
- Index(es):