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

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

2006-08-09 14:35:13, Category: Programming & Design
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.

Answers

  1. Microanalyst

    On 2006-08-09 15:12:36


    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
  2. sterno73

    On 2006-08-09 18:25:34


    my @list = split(/\s*/, $your_scalar); my $word_count = $#list;