ovedpo15 has asked for the wisdom of the Perl Monks concerning the following question:
It didn't sort uniq the array and I didn't understand why. Finally I understand why - it does not make changes on the current array, rather creates a copy and does changes on that. So I have wrote the following code:my ($k,$g,$a,$v,$f,$c) = split(/,/,$line); push(@{$href->{$v}},$a); sort(uniq(@{$href->{$v}}));
This code work as wanted, but the code does not look very good. Is it possible to achieve same logic with less lines or nicer solution? If it was possible, the first code would be great (if worked)my ($k,$g,$a,$v,$f,$c) = split(/,/,$line); my @temp_arr; if(defined($href->{$v})) { @temp_arr = @{$href->{$v}}; } push (@temp_arr,$a); @{$href->{$v}} = sort(uniq(@temp_arr));
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Understanding how sort uniq works
by Eily (Monsignor) on Jul 25, 2019 at 14:43 UTC | |
|
Re: Understanding how sort uniq works
by roboticus (Chancellor) on Jul 25, 2019 at 14:50 UTC | |
|
Re: Understanding how sort uniq works
by BillKSmith (Monsignor) on Jul 26, 2019 at 15:52 UTC | |
|
Re: Understanding how sort uniq works
by hippo (Archbishop) on Jul 26, 2019 at 09:06 UTC | |
by AnomalousMonk (Archbishop) on Jul 26, 2019 at 13:37 UTC | |
|
Re: Understanding how sort uniq works
by ikegami (Patriarch) on Jul 26, 2019 at 03:30 UTC |