in reply to Re^2: Problem in using 'ëxists" function to see if a key exists for a hash
in thread Problem in using 'ëxists" function to see if a key exists for a hash

to add a key to the hash orgin if the array element is already present in the hash as a key.

Don't you mean not present like in your code?

if (exists $orgin{$val}) { next; } else { print "$val : $key Entered the else loop\n"; push @{$orgin{$val}}, "xxxx"; $count++; }
poj
  • Comment on Re^3: Problem in using 'ëxists" function to see if a key exists for a hash
  • Download Code

Replies are listed 'Best First'.
Re^4: Problem in using 'ëxists" function to see if a key exists for a hash
by achs (Initiate) on Feb 17, 2016 at 08:52 UTC
    Sorry for the error in the question. If the array element is not present in the keys of the hash%orgin, add it as a key.But here it is not happenning but don't understand why.Please help me understand what is going wrong with the code
      array @port_list which I get by reading a input file

      Maybe your error is in the reading code which you haven't shown.
      Have you Dumped @port_list to check ?

      Update ; It looks like you may have leading spaces on the duplicates. Try adding another regex line

      foreach my $val (@port_list) { $val=~s/\s+$//; $val=~s/^\s+//; # add print "[$val]\n"; . . .
      poj
        Thanks very much. It worked!! :)