in reply to Re2: Idea vs realization
in thread passing arguments

Hmm. Interesting solution.

Turns out though that you should have developed this under strict. There is a minor bug that prevents your routine from running if you dont use your exact perparation code. The problem is that what you pass to the routine never gets used (you do $set=shift; but then iterate over @$s, which just happens to be defined as a global so it works out fine in your sample...) Anyway I fixed that and removed some of the extraneous code. See below.

My problem with this is that you have to preconstruct an array containing references to the scalars in question, which I dont really think meets the letter of my specification. Also the proconstruction is pretty cumbersome. Anyay heres your revised code, mine and some output.

use Data::Dumper; use strict; sub count_unique { print Dumper \@_; my %uniq; $uniq{0+\$_}++ foreach @_; return sprintf ( "CTU: %d unique entities (%d duplicates):\n", scalar keys %uniq, scalar ( grep { $uniq{$_} > 1 } keys %uniq ), ); } sub find_unique_items_in { my $set = shift; print Dumper $set; my (%uniq, @out) = (); for my $i (@$set) { $uniq{ $i }++; } return sprintf ( "FUI: %d unique entities (%d duplicates):\n", scalar keys %uniq, scalar ( grep { $uniq{$_} > 1 } keys %uniq ), ); } my ($x,$y,$z)=qw(a b c); print count_unique($x,$y,$z),$/; print find_unique_items_in([\$x,\$y,\$z]),$/; print count_unique($x,$y,$y),$/; print find_unique_items_in([\$x,\$y,\$y]),$/; print count_unique($x,$x,$y,$y),$/; print find_unique_items_in([\$x,\$x,\$y,\$y]),$/; print count_unique($z,$z,$z,$z),$/; print find_unique_items_in([\$z,\$z,\$z,\$z]),$/; print count_unique($x,$x,$y,$y,$z,$z),$/; print find_unique_items_in([\$x,\$x,\$y,\$y,\$z,\$z]),$/; __END__ $VAR1 = [ 'a', 'b', 'c' ]; CTU: 3 unique entities (0 duplicates): $VAR1 = [ \'a', \'b', \'c' ]; FUI: 3 unique entities (0 duplicates): $VAR1 = [ 'a', 'b', ${\$VAR1->[1]} ]; CTU: 2 unique entities (1 duplicates): $VAR1 = [ \'a', \'b', $VAR1->[1] ]; FUI: 2 unique entities (1 duplicates): $VAR1 = [ 'a', ${\$VAR1->[0]}, 'b', ${\$VAR1->[2]} ]; CTU: 2 unique entities (2 duplicates): $VAR1 = [ \'a', $VAR1->[0], \'b', $VAR1->[2] ]; FUI: 2 unique entities (2 duplicates): $VAR1 = [ 'c', ${\$VAR1->[0]}, ${\$VAR1->[0]}, ${\$VAR1->[0]} ]; CTU: 1 unique entities (1 duplicates): $VAR1 = [ \'c', $VAR1->[0], $VAR1->[0], $VAR1->[0] ]; FUI: 1 unique entities (1 duplicates): $VAR1 = [ 'a', ${\$VAR1->[0]}, 'b', ${\$VAR1->[2]}, 'c', ${\$VAR1->[4]} ]; CTU: 3 unique entities (3 duplicates): $VAR1 = [ \'a', $VAR1->[0], \'b', $VAR1->[2], \'c', $VAR1->[4] ]; FUI: 3 unique entities (3 duplicates):
but as far as I know, it's fundamentally impossible to create a parameter list that can't be stored as a data structure.

And my point is that this is wrong. The parameter list @_ is magic. It contains aliases to the items passed. A normal array contains _copies_ of the items passed. The only way that you can simulate this behaviour is to do the work around you did, which is to pass references to the items in question. But then that completely changes the data being passed and the code that must handle it. And all of this is clear from the dumper results in the code above.

Anyway, good try. :-)

Yves / DeMerphq
---
Writing a good benchmark isnt as easy as it might look.