Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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";
Bill

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151823]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (2)
As of 2026-04-19 23:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.