in reply to Trying to make the code more clear and clean
If you take a look closely, you'll see duplicates of the same group name in the same test. How to solve it?
Because you keep pushing them in without checking if that group exists already:
push @{ $href->{test} }, { group => $group, values => [ sort uniq $value, @{ $href->{values} // [] } ] };
Also, this keeps sorting every time you insert a new value:
$a{"values"} = [sort(uniq($value,@{$href->{"values"}}))];
uniq() can perhaps be eliminated if you used a hash instead of the array. And you can do the sorting *once*, after you have read/inserted your data, as a second stage processing.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Trying to make the code more clear and clean
by ovedpo15 (Pilgrim) on Jul 29, 2019 at 23:01 UTC |