The tr operator will translate one character to another.  For example:

my $string = "abc";
$string =~ tr/a/d/;
print $string;

prints
dbc;

However, it also returns the number of changes it did.  So, if you don't
give it anything to change to, you can count how  many occurrences of a
character were in the string.

my $string = "a,b,c";
my $num = $string =~ tr/,//;
print $num;

prints 2.
----- Original Message -----
From: "Helen Dynah" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, April 05, 2002 12:52 PM
Subject: Variable question


>
> Hi everybody.  I am a new user and my first question to this list is
probably a very simple one.  I am trying to count the number of commas in a
variable.  The book I am learning from doesn't cover specific information
like that.  Thanks for any help.
>
>
>
> Helen
>
>
>
> ---------------------------------
> Music, Movies, Sports, Games! Yahoo! Canada Entertainment
>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to