473,573 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

passing arg to sub problem

hi,
i am new to perl and am trying to convert the code below into a
subroutine but have a problem concering the reading of the input.
i am trying to pass an array as an argument to the subroutine. the
array is produced earlier in the program and needs to be passed to the
subroutine. @array holds LINES of words separated by whitespace. so,
$array[0] will be one line from the DATA below. the code below runs
fine as a separate program but I don't know how to pass @array as an
argument to the function. could someone help me with this simple
problem? i hope i worded it clearly.

thanks,
slash

----CODE-----------
while (<>) {
@tmp=split;
push @AoA, [@tmp];
}
for $row(@AoA) {
push @$row, $ARGV;
print "@$row\n";
}
-----DATA------

regular expressions are used by
many programs such as the
UNIX commands grep sed awk

------

thanks,
slash
Jul 19 '05 #1
3 8888
Something like:
showMe( $arr );
sub showMe{
my $ln = shift;
...
}

or

showMe( @arr );
sub showMe {
my($foo, $bar) = @_;
...
}
"slash" <sa*****@gwu.ed u> wrote in message
news:30******** *************** ***@posting.goo gle.com...
hi,
i am new to perl and am trying to convert the code below into a
subroutine but have a problem concering the reading of the input.
i am trying to pass an array as an argument to the subroutine. the
array is produced earlier in the program and needs to be passed to the
subroutine. @array holds LINES of words separated by whitespace. so,
$array[0] will be one line from the DATA below. the code below runs
fine as a separate program but I don't know how to pass @array as an
argument to the function. could someone help me with this simple
problem? i hope i worded it clearly.

thanks,
slash

----CODE-----------
while (<>) {
@tmp=split;
push @AoA, [@tmp];
}
for $row(@AoA) {
push @$row, $ARGV;
print "@$row\n";
}
-----DATA------

regular expressions are used by
many programs such as the
UNIX commands grep sed awk

------

thanks,
slash


Jul 19 '05 #2
sa*****@gwu.edu (slash) wrote in message news:<30******* *************** ****@posting.go ogle.com>...
I don't know how to pass @array as an
argument to the function. could someone help me with this simple
problem? i hope i worded it clearly.


This is FAQ: "How can I pass/return a {Function, FileHandle, Array,
Hash, Method, Regex}?"

This newsgroup does not exist (see FAQ). Please do not start threads
here.
Jul 19 '05 #3
myFunc(\@arrayO ne, \@arrayTwo); # here you are passing the array as reference
sub myFunc{
my ($arrayOneRef, $arrayTwoRef) = @_; # accepting the array as a string
my @array1 = @$arrayOneRef; # derefrencing it back into an array
my @array2 = @$arrayTwoRef;
....
}

OR

In this case you are storing the values back into an array..
my ($str1, $str2) = myFunc(\@arrayO ne, \@arrayTwo);
my @array1 = @$str1;
my @array2 = @$str2;
......
(Your myFunc wud still remain the same)
This should work..it worked for me..

Aditya...
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
4657
by: Dave | last post by:
I'm currently working on a small project (admitedly for my CS class) that compares the time difference between passing by value and passing by reference. I'm passing an array of 50000 int's. However, since in C++ an array is passed by reference by default I need to embed the array into a struct in order to pass it by value. The problem is...
58
10081
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of code... TCHAR myArray; DoStuff(myArray);
9
4771
by: justanotherguy63 | last post by:
Hi, I am designing an application where to preserve the hierachy and for code substitability, I need to pass an array of derived class object in place of an array of base class object. Since I am using vector class(STL), the compiler does not allow me to do this. I do realize there is a pitfall in this approach(size of arrays not...
8
4103
by: kalinga1234 | last post by:
there is a problem regarding passing array of characters to another function(without using structures,pointer etc,).can anybody help me to solve the problem.
7
2841
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID);...
6
3245
by: Scott Zabolotzky | last post by:
I'm trying to pass a custom object back and forth between forms. This custom object is pulled into the app using an external reference to an assembly DLL that was given to me by a co-worker. A query-string flag is used to indicate to the page whether it should instantiate a new instance of the object or access an existing instance from the...
5
1644
by: blue | last post by:
We often get connection pooling errors saying that there are no available connections in the pool. I think the problem is that we are passing around open readers all over the place. I am planning on changing this in our code and I expect this to fix our problem. We have our connection pooling set to the default number of connections...
22
25562
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to compile. <WebMethod()> _ Public Function VerifySku(ByVal skus As XmlDataDocument) As DataSet Test program : Dim cartSet As DataSet cartSet =...
6
5980
by: MSDNAndi | last post by:
Hi, I get the following warning: "Possibly incorrect assignment to local 'oLockObject' which is the argument to a using or lock statement. The Dispose call or unlocking will happen on the original value of the local." My code is: using System; using System.Collections.Generic;
12
3010
by: scottt | last post by:
hi, I am having a little problem passing in reference of my calling class (in my ..exe)into a DLL. Both programs are C# and what I am trying to do is pass a reference to my one class into a DLL function. When I try and compile the DLL I get "The type or namespace name "MyForm" could not be found. I think I have to reference the class but...
0
7744
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
7982
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. ...
1
7732
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...
0
6353
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...
1
5553
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
5255
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...
0
3695
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3691
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
989
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.