Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: Finding unique elements in inputs

by BillKSmith (Monsignor)
on Apr 22, 2023 at 15:22 UTC ( [id://11151823] : note . print w/replies, xml ) Need Help??

in reply to Finding unique elements in inputs

Although others have shown better solutions, The original post is nearly correct. The only problem is that the logic is backwards.
#!/usr/bin/perl -w use strict; @ARGV = qw(a b c c d); #remove the extra "c" my @inputs = (); my @values = (); @inputs = @ARGV; foreach my $elemnt (@inputs) { # if (grep {$_ ne $elemnt} @values) if (!grep {$_ eq $elemnt} @values) { push @values, $elemnt; } } print "@values\n";