in reply to Delete repeated Hash's / HOH's

I should have been clearer in my initial post.sorry!
This is a question of how to deal with two hash's with the same value. Not a case of having to values in a hash.

How can i handle repeated data in my hashes? Both HOH or %hash.

Here is a sample hash:

$students{"Sally Cummings"}=( { "year"=>"1", "GPA"=>"3.3", "major"=>"Undecided", "email"=>"scummings\@school.edu" }

Here is a sample HOH:

%students = (); $students{"Nick Plato"}=( { "year"=>"2", "GPA"=>"2.5", "major"=>"Phys. Ed.", "email"=>"nplato\@school.edu" } ); $students{"Mary Pitts"}=( { "year"=>"4", "GPA"=>"4", "major"=>"Economics", "major"=>"Economics", "email"=>"mpitts\@school.edu" } ); $students{"Sally Cummings"}=( { "year"=>"1", "GPA"=>"3.3", "major"=>"Undecided", "major"=>"Undecided", "email"=>"scummings\@school.edu" } $students{"Sally Cummings"}=( { "year"=>"1", "GPA"=>"3.3", "major"=>"Undecided", "major"=>"Undecided", "email"=>"scummings\@school.edu" } );

Look at the above examples closely for all repeated stuff.

Replies are listed 'Best First'.
Re: Re: Delete repeated Hash's / HOH's
by perlplexer (Hermit) on Apr 10, 2002 at 18:03 UTC
    Clear as mud...
    As RMGir already pointed out, you can't have two identical keys in a hash. So, in your case you can't have two Sallys in %students. The second assignment simply overwrites the first.

    Also, I suggest you read perldoc perldata and perldoc perldsc as I sense a fair amount of confusion on your part.

    --perlplexer
Re: Re: Delete repeated Hash's / HOH's
by RMGir (Prior) on Apr 10, 2002 at 18:05 UTC
    You won't see the repeated items, like major, since the hash will only hold the last value.
    $ perl -d Default die handler restored. Loading DB routines from perl5db.pl version 1.07 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. $students{"Mary Pitts"}=( { "year"=>"4", "GPA"=>"4", "major"=>"Economics", "major"=>"Economics", "email"=>"mpitts\@school.edu" } ); print "Mike was here..."; main::(-:1): $students{"Mary Pitts"}=( main::(-:2): { main::(-:3): "year"=>"4", main::(-:4): "GPA"=>"4", main::(-:5): "major"=>"Economics", main::(-:6): "major"=>"Economics", main::(-:7): "email"=>"mpitts\@school.edu" DB<1> n main::(-:11): print "Mike was here..."; DB<1> x %students 0 'Mary Pitts' 1 HASH(0xa038a8c) 'GPA' => 4 'email' => 'mpitts@school.edu' 'major' => 'Economics' 'year' => 4
    See? Only one major...

    Are you saying you want an error to occur when a duplicate value is attempted? A large debate occurred on p5p recently (a few months ago) about clamped hashes, but I don't remember what the outcome was, or whether the feature will be in 5.8.
    --
    Mike