use strict;
my @orig = ( qw(a a b b c 0 c d d u u),
(undef, undef, 'blink', 'blink'),
qw(0 0 v v w w a a a b b b c c c)
);
my @list;
nodupes (\@orig, \@list);
print join ' ', @list, "\n";
sub nodupes {
my ($ar1, $ar2) = @_;
my $p;
push @$ar2, grep{$_ ne 'aardvark'}
map{defined $_ ? $_ : 'undef'}
map { $p ne $_ ? $p = $_ : 'aardvark' }
@$ar1;
}
__END__
Prints --> a b c 0 c d u undef blink 0 v w a b c
####
perl -e "@list = grep{$_ ne 'aardvark'}
map{defined $_ ? $_ : 'undef'}
map{$p ne $_ ? $p = $_ : 'aardvark'}
(qw(a a b b c 0 c u u), (undef, undef), qw(0 0 v v w w));
print join ' ', @list;"
Prints --> a b c 0 c u undef 0 v w
####
use strict;
sub nodupes {
my $p;
return grep{ $_ ne '~~' } map { $p ne $_ ? $p = $_ : '~~' } @_;
}
my @orig = ( qw(a a b b c 0 c d d u u),
(undef, undef, 'blink', 'blink'),
qw(0 0 v v "0" "0" "0" w w a a a b b b c c c)
);
my @new = nodupes @orig;
print join ' ', @new, "\n";
__END__
Prints --> a b c 0 c d u blink 0 v "0" w a b c
^^
There's an undef between these two spaces.