in reply to Explain the code

This code reminded me of a perlfaq and I was right; see How can I remove duplicate elements from a list or array? (3rd question in section "Data: Arrays")

It contains an explanation which results in the code you mentioned.