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: '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 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
scalar() on it. But this cannot be the best method (too much work!).

Your take guys?

------------------------------------

I'm sure there may be a better way. My computer counted the lines in a
40mb text file in about 2 sec. Not too shabby.

my @count = split(/\s+/,$line);
print scalar(@count);

- Chris

_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to