Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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

Comment on strlen like function in perl
Download Code
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 Ven'Tatsu (Deacon) on Dec 18, 2001 at 01:49 UTC
Re: strlen like function in perl
by andye (Curate) on Dec 18, 2001 at 01:55 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 the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (10)
As of 2014-07-28 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (191 votes), past polls