Sort attachments by date in ticket metadata

I would like to sort the attachments in the ticket metadata by date. I’ve found two topics about this:

The first one seems to go in the right direction but no conclusion is reached.

Unfortunately I don’t know the first thing about perl, how can we sort the attachments?

Thank you!