Re: how to shorten this code ? x occur how many times in variable

[email protected] (Richard Lee)
Newsgroups perl.beginners
Message-ID <[email protected]>
John W. Krahn wrote:
> Richard Lee wrote:
>> Can you please tell me how to shorten this?
>>
>> my @an = split(//);
>> my @num = grep { $_ eq ':' } @an ;
>>
>> I was trying to see how many : occur in variable but didn't know how 
>> to do it fast so i did it like above...
>>
>> I would like to see as many way different ways to get this done if 
>> possible
>>
>> thank you!!
>>
>>
>> $var1 = root:x:123:/root:
>>
>> trying to see how many times : occurs in $var1..... and I could only 
>> do it above way....
>
> my $count = $var1 =~ tr/://;
>
>
>
>
> John

Talking about reinventing the wheel!!  thank you and I shall try this.. 
as I have nver tried tr before.......... thank you!!
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.