Shoot! I totally get the semi-predicate problem, and you stated the problem clearly in the OP, but I thought I had a brainwave and rewrote my UPDATED code, which had actually accounted for the problem.
So anyway, I re-read the entire thread and I sort of get why you'd want, say, a $^PRE special variable. But it is so trivial, I don't see why you'd bother. You are simply dealing with a list in pairwise fashion, using a previous value to evaluate a current value. Eliminating adjacent dupes is trivial...
@new = map { $p ne $_ ? $p = $_ : () } @orig;
except for an initial undefined value, but only because $p is initially undefined. So you define it and it works. And it's easy to remember.
$p = 'supercalifragilistic';
@new = map { $p ne $_ ? $p = $_ : () } @orig;
You could define a uniq_adj function...
use strict;
sub uniq_adj {
my $p = 'supercalifragilistic';
return map { $p ne $_ ? $p = $_ : () } @_;
}
my @orig = (undef, undef, qw(a a b b c 0 c d d u u 0 0 "0" "0" '0'
+ '0'));
my @new = uniq_adj @orig;
print "'", join ("' '", @new), "'\n";
__END__
Prints --> '' 'a' 'b' 'c' '0' 'c' 'd' 'u' '0' '"0"' ''0''
I printed with single quotes to show where undef's are being printed. Note that 0, "0", and '0' are preserved. It's very generalizable. I predefined $p, but isn't that less work than having Perl do it through a built-in? I read through the entire thread again and it seems to fit the bill. Is this kind of what you're looking for?
Regardless, cheers!
--marmot |