Q: How do I eliminate entries in Associative Arrays 
Author Message
 Q: How do I eliminate entries in Associative Arrays

Given the following Situation

%test={'a',1,'b',2,'c',3};

# how can I eliminate the tuple 'b',2 completely from the array ??
# I tried:

undef($test{'b'});
# didnt work 'b' is still in keys(%test)

-any suggestions??

Thanks in advance
-werner

--
Werner J. Schoenfeldinger          Department  for  Applied Computer Science
                                   Univ. of Economics and BA, Vienna/Austria



Thu, 01 May 1997 19:19:00 GMT  
 Q: How do I eliminate entries in Associative Arrays

Quote:

>Given the following Situation

>%test={'a',1,'b',2,'c',3};

># how can I eliminate the tuple 'b',2 completely from the array ??
># I tried:

>undef($test{'b'});
># didnt work 'b' is still in keys(%test)

First of all you want parens, not curlies to set up a hash the way you do:

%test=('a',1,'b',2,'c',3);

delete $test{'b'} does what you want.

Anno



Fri, 02 May 1997 19:35:52 GMT  
 Q: How do I eliminate entries in Associative Arrays

Quote:

> Given the following Situation
> %test={'a',1,'b',2,'c',3};
> # how can I eliminate the tuple 'b',2 completely from the array ??
> # I tried:
> undef($test{'b'});
> # didnt work 'b' is still in keys(%test)

Try using delete.

(BTW: I managed to compile perl5b1 some time back on the alpha using
gcc and the defaults supplied by Configure.)
--

Jon Connell                    


Fax        : +49 (0)89 722 27544           _/ _/      _/   _/ _/
Telephone  : +49 (0)89 722 28790          _/ _/      _/   _/ _/
Snail-Mail : Siemens AG, OeN TN ET D33   _/ _/_/_/  _/_/_/   _/_/_/
             Postfach 700071
             D-81359 Munich               SIEMENS IC DESIGN CENTER  



Fri, 02 May 1997 22:38:04 GMT  
 Q: How do I eliminate entries in Associative Arrays

:Given the following Situation
:
:%test={'a',1,'b',2,'c',3};
:
:# how can I eliminate the tuple 'b',2 completely from the array ??
:# I tried:
:
:undef($test{'b'});
:# didnt work 'b' is still in keys(%test)

See FAQ qeustion 5.8:

    What's the difference between "delete" and "undef" with %arrays?

--tom
--

I know I'm a pig-ignorant slut.  --Andrew Hume



Fri, 02 May 1997 22:11:17 GMT  
 Q: How do I eliminate entries in Associative Arrays

Quote:

>Given the following Situation

>%test={'a',1,'b',2,'c',3};

># how can I eliminate the tuple 'b',2 completely from the array ??
># I tried:

>undef($test{'b'});
># didnt work 'b' is still in keys(%test)

>-any suggestions??

delete $test{'b'}

(sorry if this is a repeat, newsfeed is still a few days behind the times)

Mike

--
The "usual disclaimers" apply.    | Meiko
Mike Stok                         | 130C Baker Ave. Ext

Meiko tel: (508) 371 0088 x124    |



Mon, 05 May 1997 23:45:48 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Nested Associative Arrays, Can they be done?

2. Number of entries in associative array?

3. Deleting entries in associative array

4. Removing associative array entries

5. Number of entries in associative array?

6. associative array or associative arrays

7. Associative array of associative arrays

8. eliminating multiple entries in a list

9. Eliminate elements from array with second array?

10. Multidimensional asociative array syntax Qs

11. Eliminating duplicates in array

12. Eliminate to another array

 

 
Powered by phpBB® Forum Software