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

Why is my hash behaving like this?

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
0
0
GB
I am looping an array of hashes and building a hash of hashes... %nbcs is the hash of hashes
Code:
    # loop and add to hash
    for(@comp){    
        # create initials from fullname
        my @init = split(/ /,$_->{'Officer'});
        my $init = substr($init[0],0,1) . substr($init[1],0,1);
        if(!exists $nbcs{$_->{'Adv_MemNo'}}{$init}){
            $xls .= ",$init";
            print "$init<br>";
            $nbcs{$_->{'Adv_MemNo'}}{$init} = 0;
        }
        $nbcs{$_->{'Adv_MemNo'}}{$init}++;  
    }

why on earth am I getting the following output?
GD
KL
GD
KL
KL
GD
CP
JC
GD
GD
KL
KL
KL
KL
KL
KL
KL
GD
KL
GD
JC
GD
JW
KL
KL
KL
GD
KL
KL
JC
KL
KL
JC
JC
KL
CP
KL
CP
KL
KL
KL
KL
KL
KL
KL
KL
CP
CP
CP
CP
CP
CP
CP
KL
JC
KL
GD
JC

There should not be any duplicates?

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
It's OK I was being an Idiot! Yeah I know nothing new there!

I needed a seperate hash for managing duplicates...
Code:
     if(!exists $officers{$init}){
            $officers{$init} = $init;
            $xls .= ",$init";
            print "$init<br>";
        }

d'oh!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Google Rank Extractor -> Perl beta with FusionCharts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top