473,322 Members | 1,431 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,322 software developers and data experts.

Subroutine Parameters and Return Values

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 1889
KevinADC
4,059 Expert 2GB
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
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...
11
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>...
10
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...
3
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...
7
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...
14
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...
0
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:...
4
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...
1
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.