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

rotor in comb?

Thread Next
From:
Marc Chantreux
Date:
August 27, 2022 15:56
Subject:
rotor in comb?
Message ID:
Ywo+ov75VKVv4UiO@prometheus.u-strasbg.fr
hello people,

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

	my %digraphs =
	slurp.lc
	.comb(/<[a..z]>+/)
	.map( *.comb.rotor( 2 => -1, :!partial ).map: *.join )
	.Bag;

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:

	slurp.lc
	.comb(/ <[a..z]> ** 2 { --pos } /)
	.Bag;

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.

regards,

-- 
Marc Chantreux
Pôle de Calcul et Services Avancés à la Recherche (CESAR)
http://annuaire.unistra.fr/p/20200

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About