Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > subroutines vs method vs function

Reply
Thread Tools

subroutines vs method vs function

 
 
BH
Guest
Posts: n/a
 
      02-27-2008
Hi,

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

Regards,

BH
 
Reply With Quote
 
 
 
 
Joost Diepenmaat
Guest
Posts: n/a
 
      02-27-2008
BH <> 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/
 
Reply With Quote
 
 
 
 
Uri Guttman
Guest
Posts: n/a
 
      02-27-2008
>>>>> "B" == BH <> writes:

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 ------ -------- 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 ---------
 
Reply With Quote
 
Joost Diepenmaat
Guest
Posts: n/a
 
      02-27-2008
Joost Diepenmaat <> writes:

> 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/
 
Reply With Quote
 
xhoster@gmail.com
Guest
Posts: n/a
 
      02-28-2008
BH <> wrote:
> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Benchmarking Python's subroutines/function Wijaya Edward Python 1 10-03-2006 03:01 PM
defining subroutines when using interpreter interactively? MackS Perl 0 03-11-2005 01:26 AM
Global subroutines fd123456 ASP .Net 6 02-04-2005 11:12 PM
Global subroutines tshad ASP .Net 7 01-26-2005 06:42 PM
References and subroutines ReaprZero Perl 1 12-04-2003 02:53 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57