The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

String::Charcount - Count the occurence of characters within a string

SYNOPSIS

 use String::Charcount qw(count percentage);

 $string = 'The lazy brown fox jumped over the cat sitting on the fence.';

 $count = count( $string );
 print 'e exists ', $count->{e}, ' times',"\n";

 $percentage = percentage( $string, $count );
 print 'e percentage - ', $percentage->{e}, '%',"\n";

DESCRIPTION

String::Charcount counts the occurence of characters within a string and calculates percentage of occurence.

FUNCTIONS

count

Counts the occurence of all characters within a string.

 $count = count( $string );
 print 'e exists ', $count->{e}, ' times',"\n";

Returns an hashref with characters as keys and occurences as values.

count_unique

Counts unique characters (case-sensitive) within a string.

 $unique = count_unique( $string );
 

Returns a string.

percentage

Calculates percentage of occurence of all characters within a string.

 $percentage = percentage( $string, [$count] );
 print 'e percentage - ', $percentage->{e}, '%',"\n";

Returns an hashref with characters as keys and percentages of occurence as values.

EXPORT

count(), count_unique(), percentage() are exportable.