@@ -5,7 +5,7 @@ local $^W = 1;
55
66use vars qw( $VERSION @ISA) ;
77
8- $VERSION = ' 1.11 ' ;
8+ $VERSION = ' 1.12 ' ;
99
1010@ISA = qw( Set::Scalar::Real Set::Scalar::Null Set::Scalar::Base) ;
1111
@@ -168,13 +168,66 @@ These methods have operator overloads:
168168
169169 $cmp = $s <=> $t;
170170
171+ =head2 Boolean contexts
172+
171173In Boolean contexts such as
172174
173175 if ($set) { ... }
176+ while ($set1 && $set2) { ... }
174177
175178the size of the C<$set > is tested, so empty sets test as false,
176179and non-empty sets as true.
177180
181+ =head2 Iterating
182+
183+ while (defined(my $e = $s->each)) { ... }
184+
185+ This is more memory-friendly than
186+
187+ for my $e ($s->elements) { ... }
188+
189+ which would first construct the full list of elements and then
190+ walk through it: the C<$s- > each> handles one element at a time.
191+
192+ Analogously to using normal C<each(%hash) > in scalar context,
193+ using C<$s- > each> has the following caveats:
194+
195+ =over 4
196+
197+ =item *
198+
199+ The elements are returned in (apparently) random order.
200+ So don't expect any particular order.
201+
202+ =item *
203+
204+ When no more elements remain C<undef > is returned. Since you may one
205+ day have elements named C<"0" > don't test just like this
206+
207+ while (my $e = $s->each) { ... } # WRONG
208+
209+ but instead like this
210+
211+ while (defined(my $e = $s->each)) { ... } # right
212+
213+ =item *
214+
215+ There is one iterator per one set which is shared by many
216+ element-accessing interfaces-- using the following will reset the
217+ iterator: elements(), insert(), members(), size(), unique(). insert()
218+ causes the iterator of the set being inserted (not the set being the
219+ target of insertion) becoming reset. unique() causes the iterators of
220+ all the participant sets becoming reset. B<The iterator getting reset
221+ most probably causes an endless loop.> So avoid doing that.
222+
223+ =item *
224+
225+ Modifying the set during the iteration may cause elements to be missed
226+ or duplicated, or in the worst case, an endless loop; so don't do
227+ that, either.
228+
229+ =back
230+
178231=head1 AUTHOR
179232
180233Jarkko Hietaniemi <jhi@iki.fi>
0 commit comments