I've read the replies to date. On the off chance that you are looking for
something more subtle than what
    $n = length $s;
gives you consider this:

    $s = <<EOS;
    thjis is a struing of
    chras p adf qwoig I caln't seem to type
    this morning
    EOS
    $n = $s =~ tr///;   # change as below
    print $n;

"tr///" expression    $n  Comment
=============    ==  ===================
tr///                              0   trivial and expected
tr///c                           75  same as length $s
tr/\t \n\r\f//c              59  excludes the whitespace

Seems like a variant of the last might be useful if you don't want to count
embedded newlines or whitespace (there is a space between the \t and the \n
above).

--
Will Woodhull
Thornhenge, SW Oregon, USA
willl.at.thornhenge.net


----- Original Message -----
From: "Malcolm Debono" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, July 17, 2002 10:51 PM
Subject: counting characters help please


> Hi,
> I am trying to count the characters (ie: we have 6 cats)  in a variable
can
> someone please help, I tried a number of ways including the following but
as
> up to now nothing seems to work.
>
> $string = $keyword;
> $count = ($string =~ tr/.//);
> or
>  $count = ($string =~ tr/\w//);
>
> Thanks in advance.
>
> Malcolm
>
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to