targetsmart has asked for the wisdom of the Perl Monks concerning the following question:
Usage: perl [switches] [--] [programfile] [arguments] -0[octal] specify record separator (\0, if no argument) -a autosplit mode with -n or -p (splits $_ into @F) -C[number/list] enables the listed Unicode features -c check syntax only (runs BEGIN and CHECK blocks) -d[:debugger] run program under debugger
I need the count of words in it, no 'wc -w' this time, because, wc -w will give me 45 I need the result 47 (which means I need to count only if a word character present in the word)I have found an answer for this,
is there any other answers#!/usr/bin/perl -n s/[^\w]+/ /g; # replace the non words with space next if(/^\s*$/); # discard sentence with only spaces $totalcount += (split(/ /) - 1); # split the sentence using space and +count it END{ print "Total: $totalcount<<\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: word count
by pc88mxer (Vicar) on Jun 03, 2008 at 16:14 UTC | |
by graff (Chancellor) on Jun 04, 2008 at 01:00 UTC | |
|
Re: word count
by moritz (Cardinal) on Jun 03, 2008 at 15:23 UTC |