in reply to Can someone Explain 2 lines of code

I know it's removing the duplicate values in an array

No, it isn't.

It is creating a hash called %count where the keys are the stringified values in the array @Clec_id and the values are the number of occurrences of each array value. Then it is printing the keys and values of that hash.

It may be true that keys %count contains the values of the original array with duplicates removed but not guaranteed. For instance, if the array contains references, they won't exist as keys in the hash; only their stringified representation will. Also, the keys of the hash are unlikely to be returned in the same order as the values of the array.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Can someone Explain 2 lines of code

Replies are listed 'Best First'.
Re: Re: Can someone Explain 2 lines of code
by Anonymous Monk on Oct 28, 2003 at 20:16 UTC
    I am sorry you are right, I was looking at another part of the code , and yes this one is calculating the number of times each value has occured in an array .. I am sorry about my totally mis typed description .. thanks again for explaninig it ...

      An apology isn't at all necessary. You already said you didn't understand it. :-)

      If you still don't understand it, can you be more specific about what you don't understand? You seem to understand arrays... do you understand hashes? The post-increment? The keys function? The loop? The $_ variable?

      -sauoq
      "My two cents aren't worth a dime.";
      
Re: Re: Can someone Explain 2 lines of code
by pg (Canon) on Oct 28, 2003 at 20:19 UTC

    Update:

    So you were adding this at the time when I was typing ;-) and obviously yours has a richer content.

    Original:

    Just to add a little bit on top of your comment. A slight change to the code, he can actually use keys %blah as the array with all duplicates removed.

Re: Re: Can someone Explain 2 lines of code
by QM (Parson) on Oct 28, 2003 at 20:22 UTC
    I misread the reply, so I put too fine a point on it...

    Not to point too fine a point on it...

    Then it is printing the keys and values of that hash.
    ...which in this case "values" is the number of times each key was seen.

    -QM
    --
    Quantum Mechanics: The dreams stuff is made of