473,978 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Subroutine Parameters and Return Values

8 New Member
I'm using a "package" type subroutine, called test_package.pl . I'm calling it from a script called split0.pl. I want to pass the $0 variable, use the subroutine to split out just the filename, and pass that filename value back to the calling script. The subroutine does the processing correctly (I've verified with print statements), but I'm having trouble getting the value passed back to the calling script.

Here's the subroutine:

Expand|Select|Wrap|Line Numbers
  1. package test_package;
  2.  
  3. sub subroutine1 {
  4.     @script = @_;
  5.     @script = split /\\/,$script[0];
  6. }
  7. return 1;
  8.  
Here's the call from the calling script:

Expand|Select|Wrap|Line Numbers
  1. require 'test_package.pl';
  2. #
  3. # call external subroutine!
  4. $full_name = $0;
  5. test_package::subroutine1($full_name);
  6. #
  7.  
I'm pretty new to all this, so I'm assuming I'm overlooking something simple. I've looked at some Perl books, but haven't figured it out yet. I'd appreciate any help.
May 6 '07 #1
1 1916
KevinADC
4,059 Recognized Expert Specialist
you are missing something. You have not assigned the return value of the subroutine/function to a variable:

Expand|Select|Wrap|Line Numbers
  1. my $var = your_function($somevalue);
you should also use an explicit return() in your function and not depend on perl to return the correct data from a sub routine


Expand|Select|Wrap|Line Numbers
  1. sub my_sub {
  2.    my ($foo) = @_;
  3.    my $blah = do something with $foo;
  4.    return($blah);
you should also start using "strict" and "warnings" in all your perl scripts for many very good reasons.
May 6 '07 #2

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

Similar topics

3
2278
by: Bill | last post by:
I've got a subroutine, defined as Private, takes two parameters, that is called lots of times from different ASP scripts. I need specific error handling when it is called from only one particular section of my code - and from the page it's called from, it's called multiple times from there, too, so I can't check by page. I thought about adding an additional parameter, but it's called so many times that it would be unwieldy to do so. ...
11
3080
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&that=this&when=now#21> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&when=now> Before I go offering it in public (and writing it into any number of the 'development kits'...
10
2361
by: Adis | last post by:
Asp.Net Visual Studio 2003 SQL Server. Hi, Obtaining Data Based Upon Multiple Selections From a ListBox... I have database in Sqlserver and ListBox (Multiple Selection Mode) in my Visual Studio Webform. I wish obtain various records from My_Store_Procedure
3
1227
by: vipul DotNet | last post by:
hi friend, I have a function which can accept 2 parameters , one as any double value second as "Y" or "N" public sub abc(byval dblvalue as double,byval strvalue as string) end sub I want the subroutine to accept only "Y" or "N" as parameter else should
7
9585
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a subroutine Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created How do I pass such a parameter Thanks in advance Richar
14
2411
by: Rich | last post by:
Yes, I need to store some values in an array type collection object that can hold 3 or more parameters per index. I have looked at the collection object, hashtable object and would prefer not to hassel with a multi-dimensional array. Is there such an object in VB.Net? Dim obj As someCollectionObj obj.Add("parmA1", "parmA2", "parmA3") obj.Add("parmB1", "parmB2", "parmB3") ....
0
1225
by: B-lv | last post by:
I have an admin script to modify data in an Access db, but when I hit the update button after changing a field, I get a "Specified argument was out of the range of valid values. Parameter name: index" error at the line where I'm declaring my 'phone' variable. This subroutine worked with another table I was working with , but I'm wondering why the numerical assignment is having problems. Thanks in advance Bill ''
4
2626
by: otterbyte | last post by:
Hi, I have a bit of code which is confusing me to no end. Here are the basics: 1) The class module is being used in the module of a form. 2) There is an instance of the object declared at the form level, and instantiated in the Load event of the form. This instance holds the "current" values (based on data in a table), and it's called ordCurrent.
1
1625
by: 2Penny | last post by:
Ladies, Gentlemen - It's been about 3 years since I translated 68000 assembly language code into 'C' and I remember that 'C' design model that I didn't like. 'C', as I understand it, was supposed to be modeled after a sort of mathematical function returning one item per function call regardless of how many parameters were passed to the function; sorta like this ; w = f(a,b,c,d,e......)
0
10358
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11833
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
11592
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10087
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8465
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7620
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6562
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
5162
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
3
3773
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.