Steve Grazzini wrote: > > On Wed, Jul 23, 2003 at 03:25:53PM -0500, Dan Muey wrote: > > That must be in perldoc sine you both had the same example > > but I couldn't find it and the perldoc your recommended Bob > > couldn't be found! > > > > I like this very much and I'm assuming it's faster than > > putting them in hash and returning the keys as an array > > since you don't have to build a hash. > > Actually you *do* build a hash. :-) > > > @unique = do { > > my %seen; > > grep !$seen{$_}++, @arr > > }; > > The advantages are that (a) it doesn't change the order > of the input array and (b) it's a common idiom that the > next programmer in line will recognize instantly. > > The hash-keys version would probably be a bit faster: > > @unique = keys %{ > my %set; > @set{ @arr } = (); # fast! > \%set; > }; > > But karma is more important than (a smidgen of) speed.
It may (or may not) be faster but it doesn't preserve the original order of the list. Besides, the OP was reading from a file and the overhead of file I/O would probably negate the speedup. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]