×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Does Perl have a '.Indexof' for counting characters in a string?

Does Perl have a '.Indexof' for counting characters in a string?

Does Perl have a '.Indexof' for counting characters in a string?

(OP)
If I used JavaScript I would know how to count characters in a string, but in Perl I'm not fimilar on how to accomplish this.


Can Perl do something similar to this?

--if ($company.index == 22)
       $company->write('\r');


What I want to do is take the string value of $company and once the string contains 22 characters add a carriage return.

Dano
dskryzer@hotmail.com

What's your major malfunction

RE: Does Perl have a '.Indexof' for counting characters in a string?

Try this:

if ( length($company) == 22 ) {
    # Add a carriage return to the end of $company.
    $company .= "\n";
}


length returns the length of the named string.  The ".=" bit is like saying '$company = $company . "\n"'.  ie, use perls concatenation operator to add the string on the right to the end of the string on the left.

Hope this helps.




--
0 1 - Just my two bits

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close