Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

strlen like function in perl

by blax (Sexton)
on Dec 18, 2001 at 01:46 UTC ( #132680=perlquestion: print w/replies, xml ) Need Help??
blax has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

Is there a function like C's strlen in perl? I have been counting strings like this:
my $string = "2002023884ks293jjksd" for ($x = 0; $string =~ /(.)/g; $x++) { ; }
Which is working out just fine. If there is not a strlen like function, is there a better way to do it?

Thanks in advance,
blax

Replies are listed 'Best First'.
Re: strlen like function in perl
by wog (Curate) on Dec 18, 2001 at 01:48 UTC

    You're looking for length.

    update: Though, if golf is what you want, I've heard y///c be used to get the length of $_. (It's one character shorter. And, IIRC, that trick is credited to Abigail.) (y///c or any of its equivilents is not reccommended for code you plan on actually using, of course.)

Re: strlen like function in perl
by andye (Curate) on Dec 18, 2001 at 01:55 UTC
Re: strlen like function in perl
by Ven'Tatsu (Deacon) on Dec 18, 2001 at 01:49 UTC
Re: strlen like function in perl
by Lucky (Scribe) on Dec 18, 2001 at 16:28 UTC
    Just another solution:
    $length=$string=~y///c
    Yet another solution:
    $length = scalar split /|/,$string

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://132680]
Approved by root
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-06-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (644 votes). Check out past polls.