Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
There's more than one way to do things
 
PerlMonks  

Re: Counting characters in a string

by matthewb (Curate)
on Mar 11, 2004 at 11:38 UTC ( [id://335858]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Counting characters in a string

The problem that you are addressing (along with a load more) is excellently solved by the Text::Autoformat module.

For simpler needs, see Text::Wrap.

MB

Replies are listed 'Best First'.
Re: Re: Counting characters in a string
by arden (Curate) on Mar 11, 2004 at 12:10 UTC
    If you wish to avoid any modules, you can do it this way:
    #!/usr/local/bin/perl use strict; use warnings; my $var = "this is just a sample of a string, there is nothing really +important in the scalar, just a lot of text"; my $pos = 9; while(( $pos = index($var, ' ', $pos)) > -1 ) { substr($var, $pos, 1) = "\n"; $pos += 10; } print "\n$var\n";
    Just remember, TIMTOWTDI.

    - - arden.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://335858]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.