in reply to How to split a document at a column

Use substr.

Something similar to this should work:

while (<>) { substr($_, 24, 0, ' '); print; }

Or, from the command line:

$ perl -i~ -pe "substr($_, 24, 0, ' ')" your_file_name_here
--

See the Copyright notice on my home node.

"The first rule of Perl club is you do not talk about Perl club." -- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: How to split a document at a column
by ikegami (Patriarch) on Mar 29, 2007 at 13:07 UTC

    Two bugs:

    • You'll die with an substr outside of string message if there are any blank or short lines.
    • You'll add the space after the newline if line is one character less than the insert point.

    Fix:

    while (<>) { chomp; substr($_, 24, 0, ' ') if length() > 24; print("$_\n"); }
    perl -i~ -ple "substr($_, 24, 0, ' ') if length() > 24" file

    Tested.