Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
This sounds simple, but my code doesn't work (prints a blank line).
#!/usr/bin/perl -w use strict; my @inputs = (); my @values = (); @inputs = @ARGV; foreach my $elemnt (@inputs) { if (grep {$_ ne $elemnt} @values) { push @values, $elemnt; } } print "@values\n";
Suspecting an initialization problem, I tried an alternate version where I pre-seeded one element in @values, but that printed every input value (not removing duplicates).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Finding unique elements in inputs
by GrandFather (Saint) on Apr 21, 2023 at 04:32 UTC | |
Re: Finding unique elements in inputs
by haukex (Archbishop) on Apr 21, 2023 at 04:42 UTC | |
Re: Finding unique elements in inputs (uniq)
by 1nickt (Canon) on Apr 21, 2023 at 12:11 UTC | |
Re: Finding unique elements in inputs
by jwkrahn (Abbot) on Apr 21, 2023 at 08:58 UTC | |
Re: Finding unique elements in inputs
by BillKSmith (Monsignor) on Apr 22, 2023 at 15:22 UTC | |
Re: Finding unique elements in inputs
by kcott (Archbishop) on Apr 23, 2023 at 02:55 UTC |