View Single Post
Old 12-11-2003, 06:09 PM   #13 (permalink)
Epsilon
Regular Contributor
 
Epsilon's Avatar
 
Join Date: Mar 2003
Location: Las Vegas, NV
Posts: 127
Epsilon is on a distinguished road
Perl makes this so simple it's almost silly.
Code:
sub count_y
{
$string = "Johnny Boy";
$count = ($string =~ tr/y/y/);
return $count;
}
This essentially just replaces every 'y' character with another 'y' character, and returns the total number of replacements to $count. Perl is beautiful.
__________________
--Epsilon--
Epsilon is offline   Reply With Quote