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
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
sc
9:24 AM
To: 'Foo Ji-Haw'; 'Win32 perl'
Subject: RE: How to best count the number of words in a sentence?
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 compla
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
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 tremendo
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 mal
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. ;)
$n