IT SOLUTIONS
Your full service technology partner! 
-Collapse +Expand
To/From Code
-Collapse +Expand Members-Only
Sign in to see member-only pages.
   ► KBTo/From GuidesPerl  Print This     

Custom Routines (Perl and PHP Cross Reference Guide)

By Mike Prestwood

Perl versus PHP: A side by side comparison between Perl and PHP.

 
Language Details
 

Language Details is kind of a catch all for stuff that didn't make it into language basics nor any other category.

Custom Routines

[Other Languages] 

Languages Focus

For non-OOP languages, a custom routine is a function, procedure, or subroutine and for pure OOP languages, a custom routine is a class method. Hybrid languages (both non-OOP and OOP) combine both.

Perl:   sub

Perl uses subs and parameters are referenced in a special array. All arguments passed to a subroutine are stored in a special @_ array. To retrieve the arguments, you have to look inside the array and extract them.

Syntax Example:
sub sayHello {
 my ($pName) = $_[0];
 print("Hello $pName!");
}
sub add {
 my ($p1) = $_[0];
 my ($p2) = $_[1];
 return $p1 + $p2;
}
PHP:  "Custom Function" function

PHP uses functions and loosely typed parameters. Function definitions can come before or after their usage so my preference when mixing PHP in with a mostly HTML page is to put the functions after the </html> tag.

Syntax Example:
function sayHello($pName) {
 echo "Hello " . $pName . "<br>";
}
 
function add($p1, $p2) {
 return $p1 + $p2;
}












Sales Website: www.prestwood.com Or visit our legacy sales site: 
legacy.prestwood.com


©1995-2025 Prestwood IT Solutions.   [Security & Privacy]