You can do something like this as demonstrated in perlfaq4:
sub uniq {
my %seen;
grep !$seen{$_}++, @_;
}
my @array = qw(one two three two three);
my @filtered = uniq(@array);
print "@filtered\n";
Outputs:
one two three
If you want to use a module, try the uniq
function from List::MoreUtils
More Related Contents:
- How do I print unique elements in Perl array?
- Remove duplicate values from JS array [duplicate]
- Difference of Two Arrays Using Perl
- How can I check if a Perl array contains a particular value?
- How can I generate all permutations of an array in Perl?
- In Perl, how can I find the index of a given value in an array?
- How can I verify that a value is present in an array (list) in Perl?
- Convert Bash script to Perl/VBS/any other windows compatible language [closed]
- Fastest way to duplicate an array in JavaScript – slice vs. ‘for’ loop
- How is Perl’s @INC constructed? (aka What are all the ways of affecting where Perl modules are searched for?)
- Specifying file to process to Perl one-liner
- How do I run a Perl script from within a Perl script?
- Perl flags -pe, -pi, -p, -w, -d, -i, -t?
- How does double arrow (=>) operator work in Perl?
- Why are Perl source filters bad and when is it OK to use them?
- Perl 5.20 and the fate of smart matching and given-when
- Return only duplicated entries from an array (case-insensitive)
- How can I convert the stringified version of array reference to actual array reference in Perl?
- How does Perl parse unquoted bare words?
- Perl build, unit testing, code coverage: A complete working example
- In Perl, how do I change, delete, or insert a line in a file, or append to the beginning of a file?
- How can I run a system command in Perl asynchronously?
- Combine two 2d arrays and have duplicate rows removed
- How do I tell what type of value is in a Perl variable?
- What should I use for a Perl script’s shebang line?
- How can I find memory leaks in long-running Perl program?
- Why do Perl variables need to start with $, %,@ (sigils)?
- Print lines from one file that are not contained in another file
- Explain the deviousness of the Perl “preamble”
- Why doesn’t Perl’s each() iterate through the entire hash the second time?