Return a hash table from a sub routine | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Return a hash table from a sub routine

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 12-20-2012
hemalathak10 hemalathak10 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 15 July 2013, 3:53 AM EDT
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
Return a hash table from a sub routine

hello,

i am new to scripting and would like to know how to return a hash table from a sub routine.
i tried the following,

Code:
my %hash_function = ();
hash_function = &return_hash();
sub return_hash
{
    my %hash = ();
      ///populate the hash
    return %hash;
}

but it dosent seem to work. Anything wrong in this??
Sponsored Links
    #2  
Old 12-20-2012
itkamaraj's Avatar
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 14 November 2014, 7:56 AM EST
Posts: 3,059
Thanks: 33
Thanked 659 Times in 638 Posts
return the reference


Code:
 
$ cat b.pl
#!/usr/bin/perl
use strict;
use warnings;
sub get_hashes();
# Get two variables back
my ($one) = get_hashes();
print "Hash Keys : ";
print "$_ " foreach keys %$one;
print "\n";
sub get_hashes() {
        my %hash1 = (
                "1a" => "b",
                "1b" => "d"
        );
        return (\%hash1);
}
 
$ perl b.pl
Hash Keys : 1b 1a

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Hash Table like implementation in unix anindyabecs UNIX for Dummies Questions & Answers 8 05-25-2011 04:44 PM
Hash table andrew.paul Programming 1 01-07-2011 10:33 AM
nested hash table arthi UNIX for Dummies Questions & Answers 0 06-27-2008 02:56 AM
Creating a Hash Table callmetheskull Programming 4 12-23-2007 03:17 PM
hash table implementations in C Language vlrk Programming 11 07-15-2007 10:33 AM



All times are GMT -4. The time now is 10:19 AM.