develooper Front page | perl.beginners | Postings from May 2008

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

Thread Next
From:
Richard Lee
Date:
May 6, 2008 22:43
Subject:
how to shorten this code ? x occur how many times in variable
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....


Thread Next


Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About