Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Returning Hash Tables in Perl Post 4168 by PxT on Thursday 19th of July 2001 04:22:39 PM
Old 07-19-2001
The "return" function can only return a reference to an array. So, I think you would have to do something like:

$a_hash_table = build_a_hash_table();

# your hash is now in %$a_hash_table
# (the hash pointed to by the $a_hash_table scalar)

# print the hash
while ( ($k, $v) = each %$a_hash_table ) {
print "$k => $v\n";
}

sub build_a_hash_table
{
my(%hash_table);
#some code to build hash table: "%hash_table" for e.g
return (\%hash_table);
}
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Passing Hash Tables to Subroutines

Hi: How do I pass a hash table down to a subroutine along with some other variables? For example, I have say a subroutine play_with_hash: sub play_with_hash { my( $var1, $var2, %my_hash ) = @_; #do stuff with %my_hash ........... } Then I want to call the subroutine... (1 Reply)
Discussion started by: mirzabhai
1 Replies

2. Programming

hash tables, pthread_key_create

I want to store a bunch of pthread_t types in a hash table, but since pthread_t is not an integer value, I cannot hash it. I was hoping to store a unique nonzero as key 0 for each thread with thread-specific data ala pthread_key_create/pthread_setspecific, but but as it turns out only the first... (2 Replies)
Discussion started by: Corona688
2 Replies

3. Programming

Compression algorithm( usage of Hash tables)

Hi All, i was browsing thru' the opensource glib(deflate/inflate) algorithms.. which i am supposed to implement. I came across Dictionary usage (Hash tables), LZ77 algorithm and Huffman coding in that.. i couldn't follow on the Hash table implementation in that. Anybody there to give some... (5 Replies)
Discussion started by: rvan
5 Replies

4. Shell Programming and Scripting

perl using hash

i want to ask is it i can use hash in perl to store a page number with a list of words which is in that page and then print it out? Example Page 1 contains a are boy cat ............. (a list of sorted words) how can i store it in a hash? Thank you (3 Replies)
Discussion started by: mingming88
3 Replies

5. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

6. Programming

Hash tables concepts

How hash tables are used to quickly locate a data record? (4 Replies)
Discussion started by: rupeshkp728
4 Replies

7. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

8. UNIX for Dummies Questions & Answers

Hash Tables of Buffers

Hello, I want to know how hash tables for buffers were implemented in Unix and now, in linux how they are implemented ? I am aware of what hashing is..also quite familiar with Unix/Linux. Special case is how device numbers comes into picture..I am curious ! If possible consider some... (0 Replies)
Discussion started by: istevan
0 Replies

9. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

10. Programming

Perl: restrict perl from automaticaly creating a hash branches on check

My issue is that the perl script (as I have done it so far) created empty branches when I try to check some branches on existence. I am using multydimentional hashes: found it as the best way for information that I need to handle. Saing multidimentional I means hash of hashes ... So, I have ... (2 Replies)
Discussion started by: alex_5161
2 Replies
Tie::SubstrHash(3pm)					 Perl Programmers Reference Guide				      Tie::SubstrHash(3pm)

NAME
Tie::SubstrHash - Fixed-table-size, fixed-key-length hashing SYNOPSIS
require Tie::SubstrHash; tie %myhash, 'Tie::SubstrHash', $key_len, $value_len, $table_size; DESCRIPTION
The Tie::SubstrHash package provides a hash-table-like interface to an array of determinate size, with constant key size and record size. Upon tying a new hash to this package, the developer must specify the size of the keys that will be used, the size of the value fields that the keys will index, and the size of the overall table (in terms of key-value pairs, not size in hard memory). These values will not change for the duration of the tied hash. The newly-allocated hash table may now have data stored and retrieved. Efforts to store more than $table_size elements will result in a fatal error, as will efforts to store a value not exactly $value_len characters in length, or reference through a key not exactly $key_len characters in length. While these constraints may seem excessive, the result is a hash table using much less internal memory than an equivalent freely-allocated hash table. CAVEATS
Because the current implementation uses the table and key sizes for the hashing algorithm, there is no means by which to dynamically change the value of any of the initialization parameters. The hash does not support exists(). perl v5.18.2 2013-11-04 Tie::SubstrHash(3pm)
All times are GMT -4. The time now is 04:35 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy