in reply to Re: 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

I updated my question, can anybody please help Even when I am, not using the 'exists' function instead when I am using an 'if' loop just match the array element with the key of the %orgin. The two strings are not matching. Even I print this, the array element and the hash key appears to be the same. I don't understand how to fix this.Please help
  • Comment on Re^2: Problem in using 'ëxists" function to see if a key exists for a hash

Replies are listed 'Best First'.
Re^3: Problem in using 'ëxists" function to see if a key exists for a hash
by poj (Abbot) on Feb 17, 2016 at 08:49 UTC
    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
      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