473,513 Members | 2,677 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running and returning a value from a subroutine

35 New Member
Howdy,

I've been trying to do a basic calculation in PERL using a subroutine however i'm confused about a few thing. In the following code what is the signifcants of the list variable "@_"

Secondly, How do I return a value, in this case the Literal, 2 to the perl compiler? At the moment, the code does nothing.

Thanks,

Expand|Select|Wrap|Line Numbers
  1. # the justAdd subroutine  CH 13
  2.  
  3.   $first = 1;
  4.   $second = 1;
  5.  
  6.  
  7. sub JustAdd {
  8.   my ($first) = shift(@_);
  9.   my ($second) = shift(@_);
  10.   return($first + $second);
  11. }
  12.  
Sep 7 '07 #1
1 1125
numberwhun
3,509 Recognized Expert Moderator Specialist
Well, in your code, you haven't called the subroutine to have it run. Try this:

Expand|Select|Wrap|Line Numbers
  1. # the justAdd subroutine  CH 13
  2. use strict;
  3. use warnings; 
  4.  
  5. my $first = 1;
  6. my $second = 1;
  7.  
  8.  
  9. sub JustAdd {
  10.   my ($first) = shift(@_);
  11.   my ($second) = shift(@_);
  12.   return($first + $second);
  13. }
  14.  
  15.  
  16. JustAdd($first, $second);
  17.  
Sep 7 '07 #2

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

Similar topics

36
28052
by: Riccardo Rossi | last post by:
Hi all! How does Python pass arguments to a function? By value or by reference? Thanks, Riccardo Rossi.
1
7415
by: Andrew Fleet | last post by:
Hi, I'm looking at returning a reference to an array I create within a subroutine. I could do this... sub foo { my @theArray; <snip>
7
3828
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D : byte) ; where A, B are inputs only, and C, D are in/out.
17
43871
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. */ Technet Script...
5
17132
by: Bob MacBob | last post by:
Hi all, I have two scripts: 1/ parser.pl which parses a text file and stuffs the relevant data into a mySQL DB - works fine no probs there 2/ importer.pl which I want to run through all the relevant files in a directory and run them through parser.pl
6
1697
by: Jeff Frederick | last post by:
Hello all, I am interested in using the value from a field to call a function. For example I have a table and one of the field names is "Function." So for each record I input the name of the function I want to run when this record is selected. Table Example: Shape Function -------------------
1
4104
by: daniel_xi | last post by:
Hi all, I am running a VS 2003 .NET project on my client machine (Win 2000 SP4, ..NET framework 1.1), running an ASP.NET application on a remote web server (Win 2000 Server, IIS 6.0, .NET framework 1.1). The application implements a Progress Bar webcontrol, that pops up in a window, using the HttpHandler interface, on the event of a button...
10
1862
by: nasau | last post by:
Perl, I have a main program which calls two subroutines (depending upon the report names).In the subroutine I am printing the data from CSV file using the format variable, Format_top prints the report header and STDOUT prints the report data. Both these subroutine runs fine individually, independent of each other. Now I have included both these...
1
1262
by: Kjell Weding | last post by:
I have this code in VB.NET (VS 2005): Module kvitteringFunk Public Sub skrivKvittering() Dim KvittPrt As String = "" Dim iType As Byte = 0 KvittPrtType(iType, KvittPrt) ' iType should now have the value 1 - BUT IS STILL 0!?!?!?!?!? ' KvittPrt should now have the value "Common" - but is still "".?!?!?!?!
0
7269
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7177
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7394
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7559
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7542
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5100
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3237
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1611
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
470
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.