How to print out the count the word in Perl?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wiinie
    New Member
    • Feb 2011
    • 47

    How to print out the count the word in Perl?

    Hi, I have a problem with counting in Perl..please help

    how can I print the 3 words and count it in the word "Dic-tion-a-ry

    I want to pirnt 3 word = Dic => count it = 3
    and Next tion => 4

    can someone give me a hand.
    thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    First of all. That's not three words. That's only one word. Second, I assume you meant syllable, but it's not even three syllables, it's four. Third, to count syllables, you need an algorithm that will break a word up into syllables. We will not do that for you here, but we can help you if you get stuck somewhere while you're creating your algorithm. But you will have to post the code you're using.

    Comment

    • Wiinie
      New Member
      • Feb 2011
      • 47

      #3
      my algorithm works fine in my code
      and I can make a syllables in 1 word.
      and can you help me how to count the word

      dic~tum~st
      and I want to cut it and count it
      count(dic).. something like this.. do you know any way in Perl that can help me



      thanks

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        I'm not even sure what it is you're counting. You say you're counting words but you're not counting words cause you only have one word.

        Comment

        • Wiinie
          New Member
          • Feb 2011
          • 47

          #5
          sorry about that . I try to count the character in the word

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            The length function will give you the amount of characters in a string.

            Comment

            • Wiinie
              New Member
              • Feb 2011
              • 47

              #7
              it doesnt work cuz the length only works if there is an array///
              I have figure out how to split it
              other question.

              Do you know how to add the array
              I have
              @array = ('Dic', 'tum','st');
              i want to add array[0] to array[1],
              so the array[1] = 'Dictum';


              can you please help me for this..

              thank you very much..

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                You can use the join function to concatenate an array. But the length function should give you the length of a string.

                Comment

                • Wiinie
                  New Member
                  • Feb 2011
                  • 47

                  #9
                  Do you know there is anyway to count the matching time
                  Dic~tum~st

                  I want to count the time that "~" sign appear..

                  thank so very much

                  Comment

                  • Wiinie
                    New Member
                    • Feb 2011
                    • 47

                    #10
                    the join function , it doesnt work

                    Code:
                    $word= "dic~tum~st";
                    @splitedWord = split(/~/, $word);
                    					print "Splited Word: @splitedWord\n";
                    					$first = @splitedWord[0];
                    					print "first : $first \n";
                    					@splitedWord[1] = join('$first', @splitedWord[1]);
                    					print "Joined @splitedWord[1]\n";

                    it doesnt work
                    Last edited by Wiinie; Mar 10 '11, 08:01 PM. Reason: type something wrong

                    Comment

                    • Rabbit
                      Recognized Expert MVP
                      • Jan 2007
                      • 12517

                      #11
                      It's not working cause you're passing a single item in the array. For a join you need to pass an array, not a single item.

                      Comment

                      • Wiinie
                        New Member
                        • Feb 2011
                        • 47

                        #12
                        can you give me an example please..
                        I am a new in Perl so there are something that I may not understand all..


                        Thanks

                        Comment

                        Working...