

o  The elements are returned in (apparently) random order. So don’t expect any particular order. 
o 
When no more elements remain undef is returned. Since you may one
day have elements named 0 don’t test just like this
while (my $e = $s>each) { ... } # WRONG! but instead like this
while (defined(my $e = $s>each)) { ... } # Right. (An undef as a set element doesn’t really work, you get "".) 
o 
There is one iterator per one set which is shared by many
elementaccessing interfaces— using the following will reset the
iterator: elements(), insert(), members(), size(),
unique(). insert() causes the iterator of the set being
inserted (not the set being the target of insertion) becoming reset.
unique() causes the iterators of all the participant sets becoming
reset. <B>The iterator getting reset most probably causes an endless
loop.B> So avoid doing that.
For delete() the story is a little bit more complex: it depends on what element you are deleting and on the version of Perl. On modern Perls you can safely delete the element you just deleted. But deleting random elements can affect the iterator, so beware. 
o  Modifying the set during the iteration may cause elements to be missed or duplicated, or in the worst case, an endless loop; so don’t do that, either. 
o Cartesian product is a product of two or more sets. For two sets, it is the set consisting of <B>ordered pairsB> of members from each set. For example for the sets
(a b) (c d e)The Cartesian product of the above is the set
([a, c] [a, d] [a, e] [b, c] [b, d] [b, e])The [,] notation is for the ordered pairs, which sets are are not. This means two things: firstly, that [e, b] is <B>notB> in the above Cartesian product, and secondly, [b, b] is a possibility:
(a b) (b c e) ([a, b] [a, c] [a, e] [b, b] [b, c] [b, d])For example:
my $a = Set::Scalar>new(1..2); my $b = Set::Scalar>new(3..5); my $c = $a>cartesian_product($b); # As an object method. my $d = Set::Scalar>cartesian_product($a, $b); # As a class method.The $c and $d will be of the same class as $a. The members of $c and $c in the above will be anonymous arrays (array references), not sets, since sets wouldn’t be able to represent the ordering or that a member can be present more than once. Also note that since the members of the input sets are unordered, the ordered pairs themselves are unlikely to be in any particular order.
If you don’t want to construct the Cartesian product set, you can construct an iterator and call it while it returns more members:
my $iter = Set::Scalar>cartesian_product_iterator($a, $b, $c); while (my @m = $iter>()) { process(@m); }o Power set is the set of all the subsets of a set. If the set has N members, its power set has 2**N members. For example for the set
(a b c)size 3, its power set is
(() (a) (b) (c) (a b) (a c) (b c) (a b c))size 8. Note that since the elements of the power set are sets, they are unordered, and therefore (b c) is equal to (c b). For example:
my $a = Set::Scalar>new(1..3); my $b = $a>power_set; # As an object method. my $c = Set::Scalar>power_set($a); # As a class method.Even the empty set has a power set, of size one.
If you don’t want to construct the power set, you can construct an iterator and call it until it returns no more members:
my $iter = Set::Scalar>power_set($a); my @m; do { @m = $iter>(); process(@m); } while (@m);
If you want to customise the display routine you will have to modify the as_string callback. You can modify it either for all sets by using as_string_callback() as a class method:
my $class_callback = sub { ... }; Set::Scalar>as_string_callback($class_callback);or for specific sets by using as_string_callback() as an object method:
my $callback = sub { ... }; $s1>as_string_callback($callback); $s2>as_string_callback($callback);The anonymous subroutine gets as its first (and only) argument the set to display as a string. For example to display the set $s as abcde instead of (a b c d e)
$s>as_string_callback(sub{join("",sort $_[0]>elements)});If called without an argument, the current callback is returned.
If called as a class method with undef as the only argument, the original callback (the one returning (a b c d e)) for all the sets is restored, or if called for a single set the callback is removed (and the callback for all the sets will be used).
The first priority of Set::Scalar is to be a convenient interface to sets. While not designed to be slow or big, neither has it been designed to be fast or compact.Using references (or objects) as set members has not been extensively tested. The desired semantics are not always clear: what should happen when the elements behind the references change? Especially unclear is what should happen when the objects start having their own stringification overloads.
Set::Bag for bags (multisets, counted sets), and Bit::Vector for fast set operations (you have to take care of the element name to bit number and back mappings yourself), or Set::Infinite for sets of intervals, and many more. CPAN is your friend.
Jarkko Hietaniemi <jhi@iki.fi>
Copyright 2001,2002,2003,2004,2005,2007,2009,2013 by Jarkko HietaniemiThis library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
perl v5.20.3  SET::SCALAR (3)  20130615 
Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.