in reply to perl prog to read a sentence and print the count of chars for each word

So what exactly have you tried so far? While we are glad to help, this looks like 'homework' so if you want some help you will need to show us what you have tried, what worked and what didn't work. This is a very trivial application for Perl and something that you should be able to tackle after reading the first few chapters of Learning Perl.

Please amend your post and we'll try to help...

  • Comment on Re: perl prog to read a sentence and print the count of chars for each word

Replies are listed 'Best First'.
Re^2: perl prog to read a sentence and print the count of chars for each word
by anita14 (Initiate) on Feb 20, 2012 at 23:19 UTC
    #!/usr/strawberry/perl/bin print ("Enter a sentence \n"); $count = 1; $str = <STDIN>; chop ($str); @array = split (' ', $str); while ($count <= @array){ $word = $array $count - 1; $lengthWord = length($word); print (" ", $lengthWord); $count++; }
      • Please reformat your post using code tags: Writeup Formatting Tips
      • Please accompany your code with some text. Why did you post this code? Does it work the way you expect? Do you want a critique of the style?