http://www.perlmonks.org?node_id=64085


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

Replies are listed 'Best First'.
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