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

Doubt on how to return a hash from one subroutine to another

hi ,
I have got a code as under :

Expand|Select|Wrap|Line Numbers
  1. sub dbcall
  2. {
  3.     my %hash;
  4.     my $i=0;
  5.     print "<<<<<<<@_>>>>>>> \n";
  6.     foreach(@_)
  7.      {
  8.          %hash=();
  9.                       if($_=~/\=/)
  10.         {
  11.          print "***$`*** \n";
  12.                      print "***$'*** \n";
  13.                                  $hash{$`} => $';
  14.                   }
  15.  
  16.  
  17.         foreach(keys %hash)
  18.                     {                                                     print "$_ => $hash{$_}";
  19.                                 }
  20.  
Actually i have got four lines of log. Each line of data i have passed to this subroutine which comes as for example say
Expand|Select|Wrap|Line Numbers
  1.            kkpd=10
  2.  
so i have matched for "equal to"
Expand|Select|Wrap|Line Numbers
  1. $hash{$`} = $'
  2.  
now all the key value pairs are put in the hash. I need to send hash as a whole to another subroutine and see the values in the hash in that subroutine. How can i do this?

Thanks,
pavan
Aug 21 '08 #1
1 1622
nithinpes
410 Expert 256MB
You can send the hash by reference to other subroutine. Call the subroutine as below:
Expand|Select|Wrap|Line Numbers
  1. mysub(\%hash);
  2.  
Inside the subroutine, get the hash from this hash reference which is sent as argument:
Expand|Select|Wrap|Line Numbers
  1. sub mysub  {
  2.    my %gethash=%{$_[0]}; # dereference the hash reference
  3.    foreach(keys %gethash) {
  4.       print "$_ : $gethash{$_}\n"; }
  5. }
  6.  
- Nithin
Aug 21 '08 #2

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

Similar topics

3
by: Casey | last post by:
Hi, I haven't being using perl for too long. Can someone explain the correct way to get the sort function to recognize an anonymous function declared as a hash value? Look at my sample code for...
6
by: chung.ley | last post by:
Hi, Another newbie question... I have to write a program that process a huge amount of data; the end results will be a number of different reports. I will prefer to write a separate...
2
by: huey_jiang | last post by:
Hi All, I need to make DLL for my new hash function in C. In myhashdll.c file, I have a function as: char *make_hash(char *in, char *out) { ...... ...... return (out);
2
by: singlal | last post by:
Hi, my question was not getting any attention because it moved to 2nd page; so posting it again. Sorry for any inconvenience but I need to get it resolved fast. Need your help! ...
28
by: dutche | last post by:
Hi, there is some kind of difference in these two statements? float num = 154.87; printf("There is : $0.0f",num); and float num = 154.87;
4
by: LyzH | last post by:
Someone else had a question on how to emulate a mouse click. I tried posting in that thread but I have something of a twist on this problem and I'm really in trouble here! If I don't get help...
5
by: Detlev808 | last post by:
Hello, I am attempting to write an awesome perl script. Before it can do anything useful, it must first be able to read in a file, and write out a file (Note: I am NOT talking about text files)....
12
by: Matt B | last post by:
I was just wondering if there is a "best" choice from the following couple of ways of returning a value from a method: 1) private HashAlgorithm GetSpecificHashAlgorithm(string hashString){ if...
1
by: lilly07 | last post by:
While new perl, I have this doubt. Can I pass arguments as below in subroutine? &test("error", "occured", $id); Strings as well as scalars? Please let me know.
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...

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.