![]() |
|
go ahead... be a heretic | |
PerlMonks |
Re: nondestructive way to look at a character in a stringby kcott (Bishop) |
on Jan 16, 2022 at 11:02 UTC ( #11140500=note: print w/replies, xml ) | Need Help?? |
G'day BernieC, I would have used index for this (rather than the previously suggested substr). With index, you are doing exactly what you show in your spec: is the character at a certain position the one you want. With substr, you are extracting a character at a certain position, and then performing a comparison operation. The amount of coding for both is the same:
A Benchmark indicated that index was roughly twice as fast as substr. I used much the same code as I showed above:
I ran this three times. All results were very close. The middle was:
— Ken
In Section
Seekers of Perl Wisdom
|
|