473,388 Members | 1,188 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,388 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 1630
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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,...
0
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...

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.