I want to report the number of times a character occurs in a string. Thanks to Is there a better way to count occurrence of char in a string?, the first part of the following works elegantly.
#!/usr/bin/env perl
use strict; use warnings;
my $string='dog
#
####
pig horse';
# https://stackoverflow.com/questions/34437248/is-there-a-better-way-to-count-occurrence-of-char-in-a-string
print join('','# occurs ',my$dummy=()=$string=~/[#]/g,' times in',"\n",$string,"\n",);
# the following yields no count at all:
print join('','# occurs ',()=$string=~/[#]/g,' times in',"\n",$string,"\n",);
Is there a way to eliminate the seemingly gratuitous declaration of the $dummy variable? I'd like to use that integer directly in join
without first declaring a variable to grab the value.