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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting from a Hash

Status
Not open for further replies.

Verbetex

Programmer
Apr 18, 2002
18
0
0
GB
My data is set up so i have a hash within a hash.

After entering into the hash all of the data, I want to delete certain elements from the main hash.

I'm using:
foreach $x (@deleteWordList)
{
delete $wordList{$x};
}

But when i search through the Hash after this for an item that should have been deleted, it is still there.

What am i doing wrong?
 
without seeing more code, it's impossible to know exactly what your missing. However, the code you've shown is syntactically correct. Just a thought: where are you getting the deleteWordList array? Does it have "\n"'s on the end of the elements?

chomp $x; just inside the for loop to get rid of the problem - if it is one.

other than that, to trouble shoot:
Code:
foreach $x (@deleteWordList){
  print &quot;deleting: --> $x <--\n&quot;;  
  if( delete $wordList{$x} ){
    print &quot;deleted!\n&quot;;
    }
  else{
    print &quot;Didn't find  key:  --> $x <--\n&quot;;
    }
}

Good luck!

--jimh
 
That's the one! Cheers mate.

I was reading in the words from a line with one word on each line.

Works now!

Cheers :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top