Sponsored Content
Top Forums Shell Programming and Scripting Perl next if @array (exclude a list of values) Post 302972007 by Skrynesaver on Thursday 28th of April 2016 09:07:07 AM
Old 04-28-2016
Hi Pravin,

That will work however, while it will use less memory than a hash, it will use a lot more cycles. you are grepping through the (potentially large array) for every line of the file.

Where you have a static list you wish check against a hash is the preferred solution as you take advantage of the hashing to very quickly return the value.
These 2 Users Gave Thanks to Skrynesaver For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl: Assigning array values..

I have to add a variable value to an array, something like this: ...... @my_array_name = $value_of_this_variable; This doesnt seem to work, any ideas why? Thanks! (4 Replies)
Discussion started by: looza
4 Replies

2. Shell Programming and Scripting

storing values in a list or array

i have a file called file.txt having the following entries. 2321 2311 2313 4213 i wnat to store these values in a list and i want to iterate the list using loop and store it in another list (1 Reply)
Discussion started by: KiranKumarKarre
1 Replies

3. Shell Programming and Scripting

perl -write values in a file to @array in perl

Hi can anyone suggest me how to write a file containing values,... say 19 20 21 22 .. 40 to an array @array = (19, 20, ... 40) -- Thanks (27 Replies)
Discussion started by: meghana
27 Replies

4. Shell Programming and Scripting

comparing list values in Perl

Hi, I have tab separated list: KB0005 1019 T IFVATVPVI 0.691 PKC YES KB0005 1036 T YFLQTSQQL 0.785 PKC YES KB0005 1037 S FLQTSQQLK 0.585 DNAPK YES KB0005 508 S ENIISGVSY 0.507 cdc2 YES KB0005 511 S ... (1 Reply)
Discussion started by: karla
1 Replies

5. Shell Programming and Scripting

Greping array values in Bash like Perl

Hi, Is there an easy way to simulate following Perl code in Bash. if ( grep {$my_value eq $_} @ARGV ){ print "Do Something\n"; } else { die "Invalid value"; } (0 Replies)
Discussion started by: paragkalra
0 Replies

6. Shell Programming and Scripting

How to get list of user into an array in perl script

Hi, cut -d: -f1,3 /etc/group >rpt.out I have a doubt in perl. right i am getting list of group user id into rpt.out file. instead i need to store it as an array in perl script. could you please tell me how can i get list of user into an array in perl script.. thanks in advance. (1 Reply)
Discussion started by: solo123
1 Replies

7. Shell Programming and Scripting

How to map the values of an array in perl?

Hi, I have 2 arrays: @names=qw(amith veena chaitra); @files=qw(file.txt file1.txt file3.txt); There is one to one relationship between names and files. There needs to be mapping created between names and files. The output should be like this: amith --> file.txt veena --->... (3 Replies)
Discussion started by: vanitham
3 Replies

8. UNIX for Advanced & Expert Users

Search and replace a array values in perl

Hi, i want to search and replace array values by using perl perl -pi -e "s/${d$i]}/${b$j]}" *.xml i am using while loop for the same. if i excute this,it shows "Substitution replacement not terminated at -e line 1.". please tell me what's wrong this line (1 Reply)
Discussion started by: arindam guha
1 Replies

9. Shell Programming and Scripting

Perl script to verify that a value is present in an array (list)

I have 2 files , i need compare both files field by field, and in the fourth field some value will be interchaged and some value will be **. ex: file1 john|0.0|4|**:25;JP:50;UY:25 file2 john|0.0|4|JP:50;**:25;UY:25 (4 Replies)
Discussion started by: veeruasu
4 Replies

10. Shell Programming and Scripting

Perl : Assigning multile hash values to a single array

I know that @food = %fruit; Works. But how do I assign %fruit and %veggies to @food ? (2 Replies)
Discussion started by: popeye
2 Replies
HASH(9) 						   BSD Kernel Developer's Manual						   HASH(9)

NAME
hash, hash32, hash32_buf, hash32_str, hash32_strn, hash32_stre, hash32_strne -- general kernel hashing functions SYNOPSIS
#include <sys/hash.h> uint32_t hash32_buf(const void *buf, size_t len, uint32_t hash); uint32_t hash32_str(const void *buf, uint32_t hash); uint32_t hash32_strn(const void *buf, size_t len, uint32_t hash); uint32_t hash32_stre(const void *buf, int end, const char **ep, uint32_t hash); uint32_t hash32_strne(const void *buf, size_t len, int end, const char **ep, uint32_t hash); DESCRIPTION
The hash32() functions are used to give a consistent and general interface to a decent hashing algorithm within the kernel. These functions can be used to hash ASCII NUL terminated strings, as well as blocks of memory. The hash32_buf() function is used as a general buffer hashing function. The argument buf is used to pass in the location, and len is the length of the buffer. The argument hash is used to extend an existing hash, or is passed the initial value HASHINIT to start a new hash. The hash32_str() function is used to hash a NUL terminated string passed in buf with initial hash value given in hash. The hash32_strn() function is like the hash32_str() function, except it also takes a len argument, which is the maximal length of the expected string. The hash32_stre() and hash32_strne() functions are helper functions used by the kernel to hash pathname components. These functions have the additional termination condition of terminating when they find a character given by end in the string to be hashed. If the argument ep is not NULL, it is set to the point in the buffer at which the hash function terminated hashing. RETURN VALUES
The hash32() functions return a 32 bit hash value of the buffer or string. EXAMPLES
LIST_HEAD(head, cache) *hashtbl = NULL; u_long mask = 0; void sample_init(void) { hashtbl = hashinit(numwanted, type, flags, &mask); } void sample_use(char *str, int len) { uint32_t hash; hash = hash32_str(str, HASHINIT); hash = hash32_buf(&len, sizeof(len), hash); hashtbl[hash & mask] = len; } SEE ALSO
free(9), hashinit(9), malloc(9) LIMITATIONS
The hash32() functions are only 32 bit functions. They will prove to give poor 64 bit performance, especially for the top 32 bits. At the current time, this is not seen as a great limitation, as these hash values are usually used to index into an array. Should these hash values be used for other means, this limitation should be revisited. HISTORY
The hash functions were first committed to NetBSD 1.6. The OpenBSD versions were written and massaged for OpenBSD 2.3 by Tobias Weingartner, and finally committed for OpenBSD 3.2. BSD
April 3, 2007 BSD
All times are GMT -4. The time now is 05:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy