blob: 5105c5a587f4b9920b6ed9c016020feff71d53e2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
use experimental 'signatures';
sub main ( $str, $char ) {
# Count the occurrences of the character in the string
my $occurrences = 0;
for my $pos ( 0 .. length($str) - 1 ) {
if ( substr( $str, $pos, 1 ) eq $char ) {
$occurrences++;
}
}
# Display the percentage of occurrences
say int( $occurrences / length($str) * 100 + 0.5 );
}
main( $ARGV[0], $ARGV[1] );
|