Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"delete $hash{$key}" in loop deletes only the only one time - why

Status
Not open for further replies.

skyglider

Programmer
Jul 9, 2000
4
BG
here is the idea:<br>I want to delete&nbsp;&nbsp;&nbsp;the keys and values from a hash<br>( the keys are elements of an array)<br>and when i use this code- it runs and deletes only the first element of the hash<br>here is the code<br><br>sub del_elementt{<br>$art=$formdata{'element'};<br>@array=split /,/,$art;<br><br>open (TEMP, &quot;/temp.txt&quot;)¦¦&error;<br>@a_file=&lt;TEMP&gt;;<br>close (TEMP);<br>foreach $f(@a_file){<br>&nbsp; @arr=split '=',$f;<br>&nbsp; $key=$arr[1];<br>&nbsp; $rez=join('=',$arr[0],$arr[2]);<br>&nbsp; $my_hash{$key}=$rez;<br>&nbsp; }<br>foreach $key(@array){<br> delete $my_hash{$key};<br>}<br><br>and it tells me that only the first element is deleted<br>when i try to use the exists funtion it tells me that only <br>the first element exist<br>but when i put the second element first it is deleted<br><br>help pls <br>i spend&nbsp;&nbsp;2 days and a night <br>about solving this problem&nbsp;&nbsp;<br>&nbsp;thank you <br>
 
You could just say undef @array - or is there some reason you need to delete one at a time? <p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top