Sponsored Content
Top Forums Shell Programming and Scripting Perl next if @array (exclude a list of values) Post 302971935 by Skrynesaver on Wednesday 27th of April 2016 09:04:50 AM
Old 04-27-2016
Any time you want to quickly check if something is in a list, use a hash...
Code:
%hash=(val1 => 1, val2 => 1,  val3 => 1,  val6 => 1, ); # hash with unwanted items as keys and values that evaluate as true
while (<>) {
 next if $hash{$_};	# values you don't want to process are skipped here
 print;			# process the rest here
}

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
HASHSTASH(3)						 libbash hashstash Library Manual					      HASHSTASH(3)

NAME
hashstash -- libbash library that implements hash data structure SYNOPSIS
hashSet <Value> <Key> <HashName> [SubHashName [...]] $retval hashGet <Key> <HashName> [SubHashName [...]] $retval hashKeys <HashName> [SubHashName [...]] hashRemove <Key> <HashName> [SubHashName [...]] hashDelete <HashName> [SubHashName [...]] DESCRIPTION
General hashstash is a collection of functions that implement basic hash data-structure in bash scripting language. The function list: hashSet Adds a value to the hash hashGet Returns a value from the hash hashKeys Returns a list of keys of the hash hashRemove Removes a key from the hash hashDelete Deletes a hash Detailed interface description follows. FUNCTIONS DESCRIPTIONS
hashSet <Value> <Key> <Hashname> [SubHashName [...]] Adds a value to the hash. Parameters: <Value> The value to set in HashName[Key]. <Key> The key for the value Value. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Value will be the value of the key Key in the hash HashName. For example if you have (or want to define) hash C, which is subhash of hash B, which is subhash of hash A, and C has a key named ckey1 with value cval1, then you should use: hashSet cval1 ckey1 A B C $retval hashGet <Key> <HashName> [SubHashName [...]] Returns the value of Key in HashName to the $retval variable. Parameters: <Key> The key that hold the value we wish to get. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Return Value: The value of the key Key in the hash HashName. The value is returned in the variable $retval. $retval hashKeys <HashName> [SubHashName [...]] Returns a list of keys of the hash HashName in the variable $retval. Parameters: <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Return Value: The value of the key Key in the hash HashName. The value is returned in the variable $retval. hashRemove <Key> <HashName> [SubHashName [...]] Removes the key Key from the hash HashName. <Key> The key we wish to remove from HashName. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. This function should also be used to remove a sub-hash from its "father hash". In that case, the key will be the name of the sub-hash. hashDelete <HashName> [SubHashName [...]] Deletes the hash HashName [SubHashName [...]]. Parameters: <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. If this function is used on a sub-hash, a key with the name of the sub-hash will remain in its "father hash" and will hold a NULL value. BUGS
A hash name can only contain characters that are valid as part of bash variable names (i.e. a-zA-Z0-9_). The same applies for hash keys. As for now, there is no way of knowing if a key represents a value or a sub-hash. If a sub-hash will be used as a key, the returned value will be its keys list. EXAMPLES
Define hash table hashA with key Akey1 with value Aval1 use: % hashSet Aval1 Akey1 Ahash Now: % hashGet Akey1 Ahash % echo $retval Aval1 % hashKeys Ahash % echo $retval Akey1 % HISTORY
The idea to write hashstash library appeared when we've discovered the full power of the bash eval function. As of the name hashstash, it has two meanings. The first, it means 'stash' of hash functions. The second is, that hashstash contains sub- hashes inside, so it looks like stash of packed information. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 02:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy