http://www.perlmonks.org?node_id=11101451

Athanasius has asked for the wisdom of the Perl Monks concerning the following question:

I only started learning Perl 6 within the last week, so please bear with me. :-)

I had a script working nicely, then I added another statement (line D in the code below) and received a run-time error message like this:

The iterator of this Seq is already in use/consumed by another Seq (you might solve this by adding .cache on usages of the Seq, or by assigning the Seq into an array)

From the documentation I gather that I have somehow created a Seq object and then attempted to iterate it a second time. But I don’t understand where or how the Seq object is being created and used.

I managed to pare down the code to the following SSCCE:

use v6; my @paths = data(); my @dirs.push: $_.split('/') for @paths; # A # @dirs.perl; # B say $_.join('/') for @dirs; # C my $depth = @dirs.map(*.elems).min; # D sub data { my $text = q:to/END/; /aardvark/bison/camel/dromedary /aardvark/bison/camel/dromedary/elephant END return $text.lines; }

Lines A, C, and D are all required to produce the error. Uncommenting line B removes the error (by caching, apparently, although I’m not sure exactly what is cached). So I have 3 questions:

  1. Where are the Seq object(s) being created and used?
  2. I tried examining the contents of @dirs using say @dirs.perl;, but that had the same effect as uncommenting line B. Is there a way to examine the contents of @dirs (like using Data::Dump in Perl5) without introducing changes?
  3. Adding line B removes the error, but feels like a kludge. What is the correct way of writing this sort of code?

In case it matters:

11:03 >perl6 -v This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d. 12:14 >

Thanks,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,