Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Counting the number of items returned by split without using a named array

by lima1 (Curate)
on May 03, 2006 at 10:09 UTC ( #547105=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://547105]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2021-01-23 12:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?