Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: How to split a document at a column

by ikegami (Patriarch)
on Mar 29, 2007 at 13:07 UTC ( [id://607238]=note: print w/replies, xml ) Need Help??


in reply to Re: How to split a document at a column
in thread How to split a document at a column

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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (1)
As of 2026-05-11 00:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.