473,396 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Function Templates in PERL

Hello,

Does any body know if PERl supports function templates just as C++ does. I have heard of object-oriented PERL. Hence, wanted to use the feature. Please give the snippet of code also in case u have any.

Thanks,
sreemakam
Sep 15 '06 #1
1 1482
Rykus
5
Hello,

Does any body know if PERl supports function templates just as C++ does. I have heard of object-oriented PERL. Hence, wanted to use the feature. Please give the snippet of code also in case u have any.

Thanks,
sreemakam
in C++ you would have:

Expand|Select|Wrap|Line Numbers
  1. int something( int arg1, int arg2 )
  2. {
  3.   ...processing...
  4. }

in PERL this is done as follows:

Expand|Select|Wrap|Line Numbers
  1. sub something
  2. {
  3.   ...processing...
  4. }
and called by putting an ampersand (&) at the front of the function name:
Expand|Select|Wrap|Line Numbers
  1. &something( val1, val2 );

Input parameters are passed via the @_ array variable.


SO a sample function would be:


Expand|Select|Wrap|Line Numbers
  1. sub ADD
  2. {
  3.   $val1 = $_[0];
  4.   $val2 = $_[1];
  5.  
  6.   return $val1 + $val2;
  7. }
  8.  
  9.  
  10. $answer = &ADD( 2, 3 );
Sep 20 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Sam | last post by:
I would like to store html templates in a database. By using perl I would like to retrive the template ask the user to fill the template and store the whole file is template + the user data in a...
1
by: C. Olive | last post by:
Environment: Classic ASP running on IIS v5.1 Scripting Language: VBScript I suppose someone would have to be somewhat familiar with Perl in order to answer this question specifically. If you...
22
by: E. Robert Tisdale | last post by:
According to the C++ FAQ Lite: http://www.parashift.com/ What is "genericity"? Yet another way to say, "class templates." Not to be confused with "generality" (which just means avoiding...
7
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
2
by: Markus Dehmann | last post by:
I'd like to process text or document templates that use "embedded C++". Here is a constructed example (the texts I have in mind are much longer and contain relatively few code blocks): ...
16
by: WittyGuy | last post by:
Hi, What is the major difference between function overloading and function templates? Thanks! http://www.gotw.ca/resources/clcm.htm for info about ]
6
by: Stuart McGraw | last post by:
I am looking for a VBA "format" or "template" function, that is, a function that takes a format string and a varying number of arguments, and substitutes the argument values into the format string...
0
by: Audrey Pratt | last post by:
Happy Holidays to you and allow us to play Santa this year with these awsome deals that in anyway you can refuse: 2000 Web Templates for only $18.00 (Savings Over $1,000.00) ...
3
by: abhishek.smu | last post by:
Given an XML like: <root> <node>8</node> <node>21</node> <node>-7</node> <node>13</node> <node>43</node> <node>2</node> </root>
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.