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

Re: Counting number of characters in a string

by chromatic (Archbishop)
on Mar 13, 2001 at 01:13 UTC ( #63956=note: print w/ replies, xml ) Need Help??

Comment on Re: Counting number of characters in a string
Re: Re: Counting number of characters in a string
by Rudif (Hermit) on Mar 13, 2001 at 04:57 UTC
    the shortest ones are the best
    Rudif
Re^2: Counting number of characters in a string
by simul (Novice) on Jan 23, 2009 at 21:46 UTC
      This does not work for me. I expect the length of the string 'abc' to be 3, but your code returns 0:
      use strict; use warnings; my $str = 'abc'; my $cnt = @{[$str =~ /(\.)/g]}; print "$cnt\n"; __END__ 0

        Remove the backslash, add the "s" modifier. And the parens aren't necessary.

        my $cnt = @{[$str =~ /./sg]};

        Cheaper alternative:

        my $cnt =()= $str =~ /./sg;
        Use the length() function.
Re^2: Counting number of characters in a string
by Anonymous Monk on Feb 05, 2013 at 04:13 UTC
    hi all, counting number of characters is so easy.. use:length($stringname); $x=length($stringname);

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (11)
As of 2014-08-22 20:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (164 votes), past polls