in reply to Counting the number of items returned by split without using a named array

don't know if it's the "most elegant way", but if you don't want to generate an array, count the blanks, e.g.:
my $entries = 1; s/\s/$entries++/eg;
  • Comment on Re: Counting the number of items returned by split without using a named array
  • Download Code

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 10:21 UTC

    No, no, no, that would modify the original string in a most probably unwanted way. And if you really wanted to do it, then probably it should have been \s+. But you do not want to do so: a match would be better suited.

      I know that of course. It is just one quick n dirty way to count blanks (therefore the "e.g." ). but the goatse thing is nicer, i must admit