Just for the sake of argument, you can also do it using the /g switch of m//.
while($string =~ /,/g){ $num++; } -----Original Message----- From: Tanton Gibbs [mailto:[EMAIL PROTECTED]] Sent: Friday, April 05, 2002 10:06 AM To: Helen Dynah; [EMAIL PROTECTED] Subject: Re: Variable question 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] -------------------------------------------------------------------------------- This email may contain confidential and privileged material for the sole use of the intended recipient. If you are not the intended recipient, please contact the sender and delete all copies. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]