Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Different kinds of Perl subroutines

Status
Not open for further replies.

ranaaich

Programmer
Jul 18, 2005
4
US
Hello All,

I'm a newbie in the Perl. I'm encountering a bit of difficulty understanding various methodology in subroutine calls. Can any one describe the arguments that are getting passed?

Pattern 1: (most common)

sub mysub{
}

Comments: Understood
-------------------------------------
Pattern 2:

sub mysub($)
{
my ($var1, $var2) = @;
.
.
}

Comments : Couldn't understand ($) in the passing argument
---------------------------------------
Pattern 3:

sub mysub(;$)
{
my ($var1, $var2) = @;
.
.
}
Comments : Couldn't understand mysub(;$)
----------------------------------------
Pattern 4:

sub mysub($;$)
{

}
Comments : Couldn't understand mysub($;$)
------------------------------------------
Pattern 5:

sub mysqub($$$$)
{
}

Comments : Couldn't understand mysub($$$$)
-------------------------------------------


Thanking all in advance.
 
all but the first example are what are called prototypes in perl. Instead of trying to explain the differences maybe this will help you:


(scroll down to the Protypes section).

Personally, I have never found a good use for prototypes and see little reason to use them. But maybe I am not experienced enough to really understand what their purpose/value is.
 
I'm going to have to second that sentiment. I've played with them a little, but have never felt I needed them.

- Andrew
Text::Highlight - A language-neutral syntax highlighting module in Perl
also on SourceForge including demo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top