develooper Front page | perl.perl6.users | Postings from August 2022

rotor in comb?

Thread Next
Marc Chantreux
August 27, 2022 15:56
rotor in comb?
Message ID:
hello people,

Here is a little raku code to count all the digraphs from some text:

	my %digraphs =
	.map( *.comb.rotor( 2 => -1, :!partial ).map: *.join )

The first .comb match words then I map them to get digraphs but I think
it is possible to move the cursor backward in the comb regex. I just
don't know how. I'm trying to write something like:
	.comb(/ <[a..z]> ** 2 { --pos } /)

The perl version of it is:

perl -lnE '
	END { say "$_ = $digraph{$_}" for
		sort { $digraph{$b} <=> $digraph{$a} }
		keys %digraph
	$_=lc; while (/([a-z]{2})/g) {++$digraph{$1}; --pos; }

Any help is very welcome.


Marc Chantreux
Pôle de Calcul et Services Avancés à la Recherche (CESAR)

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About