in reply to Insert at regular increments
Here's one very perlish way to do it, and remember to test for your `sanity' conditions - in your above code you are assuming that each input line is an even multiple of 320 characters long - the very least you should do is die() if that is not the case.
open IN, $file or die "Cannot open $file for reading; $!"; my $c = 0; my @lines = map { $c++; chomp; die "Input line $c in $file irregular:\n$_\n" if (length % 320); m/(.{320})/g } <IN>; close IN; if (@lines) { open OUT, ">$file.new" or die "Can't open $file.new for output; $!"; print $_,"\n" foreach (@lines); close OUT; }
|
|---|