Rick:
- You can't use map to count elements.
From the docs:
The callback subroutine may be called later
in the program, due to lazy evaluation. So
don't count on subroutine side-effects. For
example, a "print" inside the subroutine may
happen later than you expect.
- The reason why count() and as_list() don't work
with big sets is that those functions can't be
lazy-evaluated.
Using something like tied variables or a module
such as "Object::Realize::Later" would make this
possible, but it would also introduce _much_
complexity in the system.
- You are using map in void context.
Flavio S. Glock
Rick wrote:
>
> On Mon, Dec 06, 2004 at 02:14:38AM +0000,
[EMAIL PROTECTED] wrote:
> > map() and grep() are not affected!
>
> I think map IS affected (I haven't tested grep) the
attached script
> print the following:
>
> set1 count:
> set2 count: 101
> map set1: 0
> map set2: 101
>
> As always, thanx for your amazingly quick reply.
>
> rick
> -------------------
> #!/usr/local/bin/perl
> use DateTime;
> use DateTime::Set;
> use DateTime::Span;
>
> $|++;
> our $start=DateTime->today;
> our $end=$start->clone->add(days=>210);
> our $spanend=$start->clone->add(days=>100);
> our
$set=DateTime::Set->from_recurrence(start=>$start,end=>$end,
> recurrence=>sub
> {$_[0]->add(days=>1)});
>
> print "set1 count: ",$set->count,"\n";
> my $set2=$set->intersection(DateTime::Span
> ->from_datetimes(start=>$start,
> end=>$spanend));
> print "set2 count: ",$set2->count,"\n";
> our $count=0;
> $set->map(sub {$count++});
> print "map set1: $count\n";
> $count=0;
> $set2->map(sub {$count++});
> print "map set2: $count\n";
>