First, your post is extremely difficult to read. It looks like you're missing the </code> tags. I tried reformatting your code and output, which I added at the end of this post.
It looks like you're iterating over the keys of your hash, but not using the keys to look for anything in the array. I think you might need to change the following line:
if(exists $orgin{$val})to be the following:
if(exists $orgin{$key})Without knowing the contents of the array and hash, it will be difficult to try to help offer suggestions on what could be wrong with your code.
OP's code and output reformatted:
foreach my $key(keys %orgin) { #my $tmp_key=quotemeta "$key"; foreach my $val(@port_list) { $val=~s/\s+$//; #print "$val***********"; #my $tmp_val=quotemeta "$val"; if(exists $orgin{$val}) { #print "same key :$tmp_val\n"; next; } else { print "$val : $key Entered the else loop\n"; push @{$orgin{$val}}, "xxxx"; $count++; } } } print Dumper \%orgin;
OUTPUT: $VAR1 = { '' => 'xxxx' , ' input' => 'xxxx' , 'input' => 'ai400_INH', 'i50_TXD_p' , 'inout' => 'VIORING50', 'DVCC16', 'VPRE30', 'VCC50_p', 'VIO50_p', 'io50_MISO_p', 'io50_NCS_p', 'io50_RXD_p', 'aio33_atb_0', 'aio33_atb_3' , 'output' => 'ao400_INH_p' , ' inout' => 'xxxx' , 'inout 4:0' => 'VIO50' , ' inout 2:0' => 'xxxx' , ' output' => 'xxxx' , ' inout 4:0' => 'xxxx' };
In reply to Re: Problem in using 'ëxists" function to see if a key exists for a hash
by dasgar
in thread Problem in using 'ëxists" function to see if a key exists for a hash
by achs
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |