Monday, May 24, 2010

What is the perl command for counting words? I have a scalar assigned. Provide an example for best answer.?

okay, so I have a website that is posting a scalar of information. I want to open the scalar and count the number of words and then tell me how many words. If you give me a good example of how you use it I will give you the best choice points.

What is the perl command for counting words? I have a scalar assigned. Provide an example for best answer.?
my @list = split(/\s*/, $your_scalar);


my $word_count = $#list;
Reply:Counting the Words in a Text





Use wc with the `-w' option to specify that just the number of words be counted and output.





To output the number of words in the file `story', type:


$ wc -w story [RET]





To output counts for several files, first concatenate the files with cat, and then pipe the output to wc.





To output the combined number of words for all the files with a `.txt' file name extension in the current directory, type:


$ cat *.txt | wc -w [RET]





more info at the site below


No comments:

Post a Comment