Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Returning Hash Tables in Perl Post 4161 by mirzabhai on Thursday 19th of July 2001 03:44:33 PM
Old 07-19-2001
Computer Returning Hash Tables in Perl

Hi:

Does anybody know how to return hash tables created in a function?

I have something like so:

%a_hash_table = build_a_hash_table();

sub build_a_hash_table
{
my(%hash_table);

#some code to build hash table: "%hash_table" for e.g

return %hash_table;
}

----> This unfortunately doesn't seem to work. The hash table in the main doesn't equal the one I create in the sub routine. Any insight would be greatly appreciated. Thank you!

Smilie
 

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
HASHINIT(9)						   BSD Kernel Developer's Manual					       HASHINIT(9)

NAME
hashinit, hashinit_flags, hashdestroy, phashinit -- manage kernel hash tables SYNOPSIS
#include <sys/malloc.h> #include <sys/systm.h> #include <sys/queue.h> void * hashinit(int nelements, struct malloc_type *type, u_long *hashmask); void hashinit_flags(int nelements, struct malloc_type *type, u_long *hashmask, int flags); void hashdestroy(void *hashtbl, struct malloc_type *type, u_long hashmask); void * phashinit(int nelements, struct malloc_type *type, u_long *nentries); DESCRIPTION
The hashinit(), hashinit_flags() and phashinit() functions allocate space for hash tables of size given by the argument nelements. The hashinit() function allocates hash tables that are sized to largest power of two less than or equal to argument nelements. The phashinit() function allocates hash tables that are sized to the largest prime number less than or equal to argument nelements. The hashinit_flags() function operates like hashinit() but also accepts an additional argument flags which control various options during alloca- tion. Allocated hash tables are contiguous arrays of LIST_HEAD(3) entries, allocated using malloc(9), and initialized using LIST_INIT(3). The malloc arena to be used for allocation is pointed to by argument type. The hashdestroy() function frees the space occupied by the hash table pointed to by argument hashtbl. Argument type determines the malloc arena to use when freeing space. The argument hashmask should be the bit mask returned by the call to hashinit() that allocated the hash ta- ble. The argument flags must be used with one of the following values. HASH_NOWAIT Any malloc performed by the hashinit_flags() function will not be allowed to wait, and therefore may fail. HASH_WAITOK Any malloc performed by the hashinit_flags() function is allowed to wait for memory. IMPLEMENTATION NOTES
The largest prime hash value chosen by phashinit() is 32749. RETURN VALUES
The hashinit() function returns a pointer to an allocated hash table and sets the location pointed to by hashmask to the bit mask to be used for computing the correct slot in the hash table. The phashinit() function returns a pointer to an allocated hash table and sets the location pointed to by nentries to the number of rows in the hash table. EXAMPLES
A typical example is shown below: ... static LIST_HEAD(foo, foo) *footable; static u_long foomask; ... footable = hashinit(32, M_FOO, &foomask); Here we allocate a hash table with 32 entries from the malloc arena pointed to by M_FOO. The mask for the allocated hash table is returned in foomask. A subsequent call to hashdestroy() uses the value in foomask: ... hashdestroy(footable, M_FOO, foomask); DIAGNOSTICS
The hashinit() and phashinit() functions will panic if argument nelements is less than or equal to zero. The hashdestroy() function will panic if the hash table pointed to by hashtbl is not empty. SEE ALSO
LIST_HEAD(3), malloc(9) BUGS
There is no phashdestroy() function, and using hashdestroy() to free a hash table allocated by phashinit() usually has grave consequences. BSD
October 10, 2004 BSD
All times are GMT -4. The time now is 08:36 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy