in reply to Problem in using 'ëxists" function to see if a key exists for a hash
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' };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Problem in using 'ëxists" function to see if a key exists for a hash
by achs (Initiate) on Feb 17, 2016 at 08:34 UTC | |
by poj (Abbot) on Feb 17, 2016 at 08:49 UTC | |
by achs (Initiate) on Feb 17, 2016 at 08:52 UTC | |
by poj (Abbot) on Feb 17, 2016 at 09:34 UTC | |
by achs (Initiate) on Feb 17, 2016 at 12:25 UTC |