Click here to get back home

subroutines vs method vs function

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
subroutines vs method vs function BH 02-27-2008
Posted by BH on February 27, 2008, 5:38 pm
Please log in for more thread options
Hi,

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

Regards,

BH

Posted by Joost Diepenmaat on February 27, 2008, 5:57 pm
Please log in for more thread options

> 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/

Posted by Uri Guttman on February 27, 2008, 5:58 pm
Please log in for more thread options

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

put your question in the BODY of your message. then it reads properly
and it is easier to write replies.

subroutines vs method vs function

subs are perl level routines you code and call.

sub bar {
        print "bar was called\n" ;
}


functions are things built into perl. read perldoc perlfunc for a list
and description of them all.

methods are just perl subs that are called via an object or a class
using a object oriented call. read perldoc perlobj for more on that.

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Architecture, Development, Training, Support, Code Review ------
----------- Search or Offer Perl Jobs ----- http://jobs.perl.org ---------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

Posted by Joost Diepenmaat on February 27, 2008, 5:59 pm
Please log in for more thread options

> IOW there methods as such, just functions that get called using method
> call semantics.

That should read "there are no methods as such"

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

Posted by xhoster on February 28, 2008, 1:08 pm
Please log in for more thread options
> Hi,
>
> Can someone clarify the 3 terms wrt Perl providing with some examples?

"subroutine" and "function" are basically interchangeable. There is a
tendency to use "function" for built-in ones and "subroutine" for
user-defined ones, but that is a tendency, not a law.

Methods are subroutines invoked in an object-oriented way.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.

Similar ThreadsPosted
FAQ 7.20: How do I redefine a builtin function, operator, or method? November 10, 2004, 12:03 am
FAQ 7.20: How do I redefine a builtin function, operator, or method? November 19, 2004, 6:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? March 10, 2005, 12:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? May 29, 2005, 5:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? September 3, 2005, 10:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? November 1, 2005, 11:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? January 21, 2006, 6:03 pm
FAQ 7.20 How do I redefine a builtin function, operator, or method? September 8, 2006, 9:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? November 4, 2006, 9:03 am
FAQ 7.20 How do I redefine a builtin function, operator, or method? March 3, 2007, 9:03 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap