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

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Return a hash table from a sub routine

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 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 Unix and Linux 12-20-2012
itkamaraj's Unix or Linux Image
itkamaraj itkamaraj is offline Forum Advisor  
^Kamaraj^
 
Join Date: Apr 2010
Last Activity: 30 December 2014, 10:04 PM 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 Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Unix or Linux Image 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 03:44 PM
Hash table andrew.paul Programming 1 01-07-2011 09:33 AM
nested hash table arthi UNIX for Dummies Questions & Answers 0 06-27-2008 01:56 AM
Creating a Hash Table callmetheskull Programming 4 12-23-2007 02:17 PM
hash table implementations in C Language vlrk Programming 11 07-15-2007 09:33 AM



All times are GMT -4. The time now is 11:09 PM.