Brendan L. - 1 year ago 45

Perl Question

I have been looking for a way to convert a set into a sorted array.

I have found a solution but it seems a little bit rediculous:

`use Set::Scalar;`

Set::Scalar->as_string_callback(sub{join("\n", sort $_[0]->elements)});

#above formats print so that a line is added between each element

... #assume things are added to the set in this code

my @arr = split("\n", "$set"); #array contains each sorted element of the set

my only issue is that in my eyes this shouldn't be a fast/memory efficient method of doing this. Please let me know if you have any advice. Thank you in advance.