Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Counting number of characters in a string

by t0mas (Priest)
on Mar 13, 2001 at 12:51 UTC ( #64085=note: print w/ replies, xml ) Need Help??


in reply to Counting number of characters in a string

Yet Another Silly Way Of Counting Characters In A String (YASWOCCIAS):

$_="YASWOCCIAS"; s/./+1/g; print eval;


/brother t0mas


Comment on Re: Counting number of characters in a string
Download Code
Re: Re: Counting number of characters in a string
by I0 (Priest) on Mar 13, 2001 at 13:19 UTC
    Shouldn't that be s/./+1/gs;
      $_="YASWOCCIAS"; don't contain any newlines so it doesn't matter in this case. In other cases it might, depending on how you define "character" in your application. For some apps (like word processors), s/\S/+1/g; might be the right choise if you like to use this algorithm in your production environment... :-)

      /brother t0mas

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2015-07-05 19:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (67 votes), past polls