Re: How to best count the number of words in a sentence?

2006-03-26 Thread Barry Dancis
I like your idea but, I think you will overcount when there are leading and trailing spaces and undercount when there are only commas, semicolons etc. How about $text =~ s/^\W+|\W+$//g; $number = $text =~ m/(\W+)/sg + 1; Chris Wagner wrote: What the hell, I'll give my version too. ;)

Re: How to best count the number of words in a sentence?

2006-03-24 Thread Eric Amick
On Thu, 23 Mar 2006 12:05:07 -0800, you wrote: This is probably a fun trivial question: I'd like to count the number of words in a string. My command: my $count = split(/\s+/,$line); works. But Perl complains about: Use of implicit split to @_ is deprecated It works, but it's deprecated. I can

RE: How to best count the number of words in a sentence?

2006-03-24 Thread Chris
Eric Amick wrote: If you've forgotten, a negative third argument forces split to produce all of the possible fields, keeping trailing null fields. In particular, it ignores the size of the destination list. I've more often seen this empty list idiom in conjunction with m//g--not that it's

Re: How to best count the number of words in a sentence?

2006-03-24 Thread Chris Wagner
What the hell, I'll give my version too. ;) $number = $text =~ m/(\s+)/sg + 1; Where $text is the entire document or whatever. Instead of counting ur fingers, u can count the spaces between ur fingers and add one. -- REMEMBER THE WORLD TRADE CENTER ---= WTC 911 =-- ...ne cede malis

RE: How to best count the number of words in a sentence?

2006-03-23 Thread Chris
Hi all, This is probably a fun trivial question: I'd like to count the number of words in a string. My command: my $count = split(/\s+/,$line); works. But Perl complains about: Use of implicit split to @_ is deprecated It works, but it's deprecated. I can assign split to an array, then do a

RE: How to best count the number of words in a sentence?

2006-03-23 Thread Furnish, Trever G
Just ask for the scalar. Not that I'm saying this is the best way, but at least you're not keeping the array: my $count = scalar split(/\s+/,$line); -t. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Chris Sent: Thursday, March 23, 2006 9:24 AM To: