in reply to most efficient regex to delete duplicate words
This solution keeps the order, dedupes throughout the entire string, and doesn't use any regexes, and I'd bet it's a good deal quicker than any regex solution. Of course, you'll want to measure if you want to be sure.#!/usr/bin/perl -w use strict; my $test = "alpha beta beta gamma gamma gamma delta"; my %seen; my @out; for ( split( " ", $test ) ) { push( @out, $_ ) unless $seen{$_}++; } print join( " ", @out ), "\n";
xoxo,
Andy
--
<megaphone>
Throw down the gun and tiara and come out of the float!
</megaphone>
|
|---|