Not only does it keep your parameter lists trim, it lets you store your data sets so you can use them again.sub find_unique_items_in { my $set = shift; my (%uniq, @out) = (); for $i (@$s) { $uniq{ $i }++; } push @out, sprintf ( "%d unique entities (%d duplicates):\n", scalar keys %uniq, scalar ( grep { $uniq{$_} > 1 } keys %uniq ), ); for $i (sort keys %uniq) { push @out, sprintf ("%-16s -- %d", $i, $uniq{$i}); } return (join ("\n", @out)); } @list = (0) x 10; for (1..10) { $set = []; push @set_list, $set; for $i (0.. rand(5)+10) { push @$set, \$list[ rand @list ]; } } for $s (@set_list) { print "\n", '-'x72 ,"\n\n"; print join ("\n", @$s), "\n\n"; print &find_unique_items_in ($s), "\n"; }
Now, I don't pretend that the above is an exhaustive search for matching entities, 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 thinking about those data structures -- especially the possibility of using them again -- helps you build well-organized code.
In reply to Re2: Idea vs realization
by mstone
in thread passing arguments
by mstone
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |