Please learn how to provide an MCVE (How to create a Minimal, Complete, and Verifiable Example?) or
SSCCE (Short, Self-Contained, Correct Example) — two names and links for the same basic idea.
The uniq
function does work. Here is a completed, marginally fixed variant of your code converted into an MCVE.
listuniq.pl
#!/usr/bin/env perl
use strict; # Always use these
use warnings;
my @urls = ( 6, 6, 6, 6, 6, 6, 6, 6, 6 );
use List::MoreUtils qw(uniq);
print "Before:\n";
print "$_\n" for @urls; # Note the @ is missing
my @unique1 = uniq(@urls);
print "After:\n";
print "$_\n" for @unique1; # Note the @ is missing
@urls = ();
push @urls, "http://www.google.com/", "http://www.yahoo.com/" for (1..6);
print "Before:\n";
print "$_\n" for @urls;
@unique1 = uniq(@urls);
print "After:\n";
print "$_\n" for @unique1;
The @
symbols in print "@$_\n"
lead to complaints because of the use strict;
. Unless you were really planning something very fancy, you need to (a) use use strict;
and use warnings;
and (b) pay heed to them.
Example run
$ perl listuniq.pl | so
Before:
6
6
6
6
6
6
6
6
6
After:
6
Before:
http://www.google.com/
http://www.yahoo.com/
http://www.google.com/
http://www.yahoo.com/
http://www.google.com/
http://www.yahoo.com/
http://www.google.com/
http://www.yahoo.com/
http://www.google.com/
http://www.yahoo.com/
http://www.google.com/
http://www.yahoo.com/
After:
http://www.google.com/
http://www.yahoo.com/
$
Other possibilities
This being Perl, TMTOWTDI — There's More Than One Way To Do It. That includes more than one way of writing code that produces unexpected results — see the other answer and commentary to the other answer for other possible ways to write code that gives confusing results. Because you've not provided an MCVE, it is hard — essentially futile — for us to guess which option you've taken to get the unexpected result. You will always improve your chances of getting the most relevant answer on SO (or any similar site) by providing a question which includes the minimal code necessary to reproduce the result you see.