Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: problem count the number of words -- oneliner

by kschwab (Vicar)
on Dec 26, 2018 at 16:40 UTC ( [id://1227717]=note: print w/replies, xml ) Need Help??


in reply to Re: problem count the number of words -- oneliner
in thread problem count the number of words

Here's an alternative:
perl -ne 's/\W+/$i++/eg;END{print "$i\n"}' f1 f2

Replies are listed 'Best First'.
Re^3: problem count the number of words -- oneliner
by pme (Monsignor) on Dec 26, 2018 at 17:16 UTC
    Hi kschwab,

    Are you sure? This one gives the same result like wc.

    perl -ne 's/\S+/$i++/egi;END{print "$i\n"}' f1 f2
      Guess it depends on what OP means by "all words", but sure.
      # works like wc perl -ne 's/\s+/$i++/eg;END{print "$i\n"}' f1 f2
      Not sure why you have the "i" modifier.
        You are right, we do not need "i".

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1227717]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found