http://qs321.pair.com?node_id=335858


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 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.