Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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:


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,

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:
    Yet another solution:
    $length = scalar split /|/,$string

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://132680]
Approved by root
[choroba]: That still doesn't make it offensive
[LanX]: of course not
[LanX]: it's pretty ironic if you know the character
choroba likes the movie
[choroba]: Lady_Aleena Do you really need to say "WorldBuilder" after having said "WorldBuilding"?
[LanX]: have to watch it again :)
[Lady_Aleena]: choroba, the tables in that group of modules is from the World Builder's Guidebook, so I thought it best to add the name of the book to the name of the module.

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2017-05-24 22:22 GMT
Find Nodes?
    Voting Booth?