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
hash(3) 						     Library Functions Manual							   hash(3)

NAME
hash - hash database access method SYNOPSIS
#include <sys/types.h> #include <db.h> DESCRIPTION
The routine dbopen is the library interface to database files. One of the supported file formats is hash files. The general description of the database access methods is in dbopen(3), this manual page describes only the hash specific information. The hash data structure is an extensible, dynamic hashing scheme. The access method specific data structure provided to dbopen is defined in the <db.h> include file as follows: typedef struct { u_int bsize; u_int ffactor; u_int nelem; u_int cachesize; u_int32_t (*hash)(const void *, size_t); int lorder; } HASHINFO; The elements of this structure are as follows: bsize Bsize defines the hash table bucket size, and is, by default, 256 bytes. It may be preferable to increase the page size for disk- resident tables and tables with large data items. ffactor Ffactor indicates a desired density within the hash table. It is an approximation of the number of keys allowed to accumulate in any one bucket, determining when the hash table grows or shrinks. The default value is 8. nelem Nelem is an estimate of the final size of the hash table. If not set or set too low, hash tables will expand gracefully as keys are entered, although a slight performance degradation may be noticed. The default value is 1. cachesize A suggested maximum size, in bytes, of the memory cache. This value is only advisory, and the access method will allocate more mem- ory rather than fail. hash Hash is a user defined hash function. Since no hash function performs equally well on all possible data, the user may find that the built-in hash function does poorly on a particular data set. User specified hash functions must take two arguments (a pointer to a byte string and a length) and return a 32-bit quantity to be used as the hash value. lorder The byte order for integers in the stored database metadata. The number should represent the order as an integer; for example, big endian order would be the number 4,321. If lorder is 0 (no order is specified) the current host order is used. If the file already exists, the specified value is ignored and the value specified when the tree was created is used. If the file already exists (and the O_TRUNC flag is not specified), the values specified for the parameters bsize, ffactor, lorder and nelem are ignored and the values specified when the tree was created are used. If a hash function is specified, hash_open will attempt to determine if the hash function specified is the same as the one with which the database was created, and will fail if it is not. Backward compatible interfaces to the routines described in dbm(3), and ndbm(3) are provided, however these interfaces are not compatible with previous file formats. RESTRICTIONS
Only big and little endian byte order is supported. ERRORS
The hash access method routines may fail and set errno for any of the errors specified for the library routine dbopen(3). RELATED INFORMATION
btree(3), dbopen(3), mpool(3), recno(3) Dynamic Hash Tables, Per-Ake Larson, Communications of the ACM, April 1988. A New Hash Package for UNIX, Margo Seltzer, USENIX Proceedings, Winter 1991. delim off hash(3)
All times are GMT -4. The time now is 11:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy