On Sun, Apr 13, 2008 at 12:35 AM,  <[EMAIL PROTECTED]> wrote:
> Hi,
>  How do I construct a regex to count the number of 'a' within a scalar 
> variable such as the undermentioned.
>  One method I can think of is to split the scalar string into a list and then 
> do the counting but I just feel that this in not necessary.
snip

There are two good solutions that I am aware of.  You should use the
first if you are counting single characters and the second otherwise:

my $count = $str =~ tr/a//;
my $count = () = $str =~ /a/g;


-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to