in reply to Counting the number of items returned by split without using a named array
Why not just count the instances of whitespace?
my $str = "this is a test string"; my $cnt = 1; # num tokens = whitespace + 1 ++$cnt while $str =~ /\s+/g; print $cnt, "\n"; # prints 5
-- Tanalis
#include www.liquidfusion.org.uk
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Counting the number of items returned by split without using a named array
by blazar (Canon) on May 03, 2006 at 11:07 UTC | |
by Hue-Bond (Priest) on May 03, 2006 at 13:38 UTC | |
by blazar (Canon) on May 03, 2006 at 13:47 UTC |
In Section
Seekers of Perl Wisdom