Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re: Counting characters in a string

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

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.


Replies are listed 'Best First'.
Re: Re: Counting characters in a string
by arden (Curate) on Mar 11, 2004 at 17: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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://335858]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2020-09-23 07:20 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (130 votes). Check out past polls.