in reply to Counting words
Your array only has a single element. I'll show how you would split each big string into smaller strings of 2 letters each using a regular expression. Each 2-letter word is stored in a hash.
use warnings; use strict; my $length = 2; my $str = "BEBEBEHUHUHUJJFAFALL"; my %cnt; while ($str =~ /(.{$length})/g) { $cnt{$1}++; } print "Found:\n"; print "$_ $cnt{$_}\n" for sort keys %cnt; __END__ Found: BE 3 FA 2 HU 3 JJ 1 LL 1
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Counting words
by bisimen (Acolyte) on Nov 04, 2017 at 18:09 UTC | |
by Laurent_R (Canon) on Nov 05, 2017 at 00:17 UTC |
In Section
Seekers of Perl Wisdom