in reply to Finding unique elements in inputs

grep can only return anything if it has something to chose from. @value starts out empty so grep can never return anything except an empty list so the if expression can never be true so @value never gets any content.

The usual way to check if something has been seen before is to use a hash:

#!/usr/bin/perl -w use strict; my @inputs = qw(first second third fourth fifth first); my %found; my @values; for my $element (@inputs) { if (!$found{$element}) { push @values, $element; ++$found{$element}; } } print "@values\n";

Prints:

first second third fourth fifth
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond