in reply to Printing Fixed Width Strings and Spliting String into Multiple Lines

To split string $s to lines of 100 characters long do:
$s=~s/(.{100})/$1\n/g;
  • Comment on Re: Printing Fixed Width Strings and Spliting String into Multiple Lines
  • Download Code

Replies are listed 'Best First'.
Re^2: Printing Fixed Width Strings and Spliting String into Multiple Lines
by oko1 (Deacon) on Feb 08, 2012 at 06:09 UTC

    There's no reason to invoke something as heavy-duty as the regular expression engine when all you're working with is substrings of a given length.

    my $s; print "$s\n" while $s = substr $str, 0, 100, '';
    -- 
    I hate storms, but calms undermine my spirits.
     -- Bernard Moitessier, "The Long Way"
      Hey oko1,

      I just gave your little snippet a try and it worked without any problems... Thanks!


      Thanks,
      Matt