in reply to how to Insert a newline character in a sentence

Welcome to the perl community! Try looking at substr in perlfunc.

Update: you may also get something out of the -p and -i switches. See more in perlrun.

  • Comment on Re: how to Insert a newline character in a sentence

Replies are listed 'Best First'.
Re^2: how to Insert a newline character in a sentence
by Selvakumar (Scribe) on Jul 23, 2009 at 12:38 UTC
    Try this
    while (<DATA>) { $var=$_; $var=~s/(.{10})/$1\\n/; print "$var"; } __DATA__ dgbjhdghjdfgjhd dfgjdjfghjkdhgdfg dgbhgdfjgjhgdfgdfg ghgjgglhkdjghkdhgk

      update: Or, to insert newlines at the 10th position and avoid double spacing lines of 9 characters, perhaps this

      use strict; use warnings; while (<DATA>) { my $var=$_; $var=~s/(.{9})/$1\n/; print "$var"; } __DATA__ dgbjhdghjdfgjhd dfgjdjfghjkdhgdfg dgbhgdfjgjhgdfgdfg ghgjgglhkdjghkdhgk