Sunday, April 19, 2020

Count Vowels and Consonants in a String in Perl

I wrote this program to ask the user to give a string and then the program will count the number of vowels and consonants using Perl programming language.

I am currently accepting programming work inventory system, enrollment system, accounting system, payroll system, information system, website design and development using WordPress, IT projects, school and application development, programming projects, thesis, and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details. If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.

Here in Bacolod City, Negros Occidental I also accepting computer repair, web development using WordPress, Computer Networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com

My programming website is http://www.jakerpomperada.blogspot.com

I am also a book author you can purchase my books on computer programming and information technology in the following links below.

https://www.mindshaperspublishing.com/

https://www.unlimitedbooksph.com/

Program Listing

# vowels_consonants_string.pl
# Author   : Jake R. Pomperada,MAED-IT,MIT
# Date     : April 8, 2020   Wednesday  6:41 PM
# Location : Bacolod City, Negros Occidental
# Email    : jakerpomperada@gmail.com
# Website  : http://www.jakerpomperada.com

sub in_array {
my ($arr,$search_for) = @_;
return grep {$search_for eq $_} @$arr;
}
  

    print("\n");
    print("\tCount Vowels and Consonants in a String in Perl");
    print("\n\n");
    print("\tEnter a String : ");
    chomp($str=<STDIN>);

    $string = lc($str);
    @vowels = ("a","e","i","o","u");
    @consonants=("b","c","d","f","g","h","j","k","l"
                ,"m","n","p","q","r","s","t","v","w","x","y","z");
    $len = length($string);
    $num1 = 0;
  
    @strarr = split(//, $string);
   
    for($i=0; $i<$len; $i++){

        if(in_array(\@vowels, $strarr[$i]))
        {
            $num1++;
        }
      
        if(in_array(\@consonants, $strarr[$i]))
        {
            $num2++;
        }
    }
    print("\n");
    print("\tString given          : $str");
    print("\n\n");
    print ("\tNumber of Vowels      : $num1\n"); 
    print ("\tNumber of Consonants  : $num2\n"); 
    print("\n\n");
    print("\t\tEnd of Program");

    print("\n\n");

No comments:

Post a Comment