Hi,
I came across these bits of code on StackOverflow the other day, both of which count the occurrence of a character in a string, and for the life of me, I don't understand what's going on, or why all those steps are necessary:
If the character is constant, the following is best:If the character is variable, I'd use the following:my $count = $str =~ tr/y//;my $count = length( $str =~ s/[^\Q$char\E]//rg );
Can anyone help me understand what's going on here?
Tom Melly, pm (at) cursingmaggot (stop) co (stop) ukmap{$a=1-$_/10;map{$d=$a;$e=$b=$_/20-2;map{($d,$e)=(2*$d*$e+$a,$e**2 -$d**2+$b);$c=$d**2+$e**2>4?$d=8:_}1..50;print$c}0..59;print$/}0..20
In reply to Confused by RegEx count by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |