diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-06-13 13:00:49 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-13 13:00:49 +0100 |
| commit | a6786ef66f32c068262a2c03f961da603d2dc644 (patch) | |
| tree | 1c9d8c429d065f5efa8d746a6e954e9887c676cc | |
| parent | 3d65552202e834fd4960acb6b2127b848f1fa289 (diff) | |
| parent | f22b622d5dba4ae7ca7ac4832bc0d56d71605490 (diff) | |
| download | perlweeklychallenge-club-a6786ef66f32c068262a2c03f961da603d2dc644.tar.gz perlweeklychallenge-club-a6786ef66f32c068262a2c03f961da603d2dc644.tar.bz2 perlweeklychallenge-club-a6786ef66f32c068262a2c03f961da603d2dc644.zip | |
Merge pull request #10254 from robbie-hatley/rh273
Update to my Perl solution to 273-1, 2024-06-12.
| -rwxr-xr-x | challenge-273/robbie-hatley/perl/ch-1.pl | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/challenge-273/robbie-hatley/perl/ch-1.pl b/challenge-273/robbie-hatley/perl/ch-1.pl index 03c97c45fe..31b81adefd 100755 --- a/challenge-273/robbie-hatley/perl/ch-1.pl +++ b/challenge-273/robbie-hatley/perl/ch-1.pl @@ -71,9 +71,7 @@ Output is to STDOUT and will be each input followed by the corresponding output. # What is the percentage, to the nearest integer, # of a given character in a given string? sub pct_chr_in_str ($str, $chr) { - my $length = length($str); - my @matches = $str =~ m/$chr/g; - lround(100*(scalar(@matches)/$length)); + lround(100*(scalar(@{[$str =~ m/$chr/g]})/length($str))); } # ------------------------------------------------------------------------------------------------------------ |
