> > > > sub unique{ [ keys {map { $_{$_} = 1 } @_ }] } > ^^^^^^^^^^^^^^^^^^^^^^ > > This returns a list of the results of the block { $_{$_} = 1 } > as evaluated for each value in @_. > > But the value of the expression $_{$_} = 1 is always 1, to > your map() is returning a list of 1's. This is obviously > not suitable for converting to a hash to pass to keys(). > > You probably want: > > map { ($_ => 1) } @_; > > This creates a list of (key, 1) pairs for each element in @_. > So if @_ contains 'foo','bar','baz', the map output list > will be:
This has enligtened me somewhat as I spotted the keys %{{map {($_ => 1)} @_}} method after I had made the post but I was trying it doing this [ keys %{{map { $_{$_} = 1 } @_ }}] which as stated above is complete bollocks so thanks for the pointer. I need to read more at perldoc -f map. Something I lack a lot in is the different methods for record construction. > > 'foo', 1, 'bar', 1, 'baz', 1 > > Now, you can create a ref to an anonymous hash out of that > list by: > > {map {($_ => 1)} @_} > > To dereference that to a hash to pass to keys(), you would use: > > %{{map {($_ => 1)} @_}} > > Now the final sub is: > > sub unique { keys %{{map {($_ => 1)} @_}} } > > (I removed the square brackets to return a list instead of an > array ref. Your choice.) After I made the mods as suggested below. sub GrepMe { [keys %{{map {($_ => 1)} @_}}] } sub GrepMe3 { [ grep { not $\{$_}++ } @_ ] } I benchmarked the two and the this is the results. Checking with array Sizes 249 and 2599999 Benchmark: timing 500000 iterations of GrepMe, GrepMe3... GrepMe: 3 wallclock secs ( 2.21 usr + 0.00 sys = 2.21 CPU) @ 226039.78/s (n=500000) GrepMe3: 2 wallclock secs ( 2.06 usr + 0.00 sys = 2.06 CPU) @ 242483.03/s (n=500000) The Functions return SAME lists They also have the same count of elements: 12 Although the map is faster than the original unique routines the grep is still the DB's. I suppose I should now look into the relative merits of one above the other. Harry __________________________________________________ Do You Yahoo!? LAUNCH - Your Yahoo! Music Experience http://launch.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]