Computer Science Canada Need a vim / perl guru |
Author: | btiffin [ Thu Jun 26, 2008 8:27 pm ] | ||||||||||
Post subject: | Need a vim / perl guru | ||||||||||
Hello, I'm doing some sample sources for the OpenCOBOL project. I'd like to figure out a vim trick to resequence the column 1-6 numbers. Starting with
I'd like to get to
The backslashes on the format specs gets around vim substitution, not sent to perl Attempting
supposed to give
but I'm getting Ctrl-M's at the end of lines that have data (some runs), and no newline on source lines that are empty. 00003000040 kinda thing. The substr doesn't seem to like empty lines so much? - probably anything under 7 spaces?
So, the question is; is this the vim filter? Can I tweak perl to use different line endings? Can I chop or chomp or substr with -1 and add a \n to the formatted print or ... can I force the newline on empty $_ somehow? Thanks in advance if you help save me digging through TFManuals. Cheers P.S. vim 7.1, perl 5.10.0, Debian 4 lenny P.P.S. By the way, if it's more than a one-liner (possibly with a setting) than I'm not that interested and I'll just do it awk ![]() |
Author: | btiffin [ Thu Jun 26, 2008 9:25 pm ] | ||
Post subject: | Re: Need a vim / perl guru | ||
Hi, So far I'm using
for the Perl part, but that's going to be harder to type, so ... I'll still take some guru advice on this one. Umm, and then post it to the OpenCOBOL forum to try and look smarter than I am ... you know how it goes Cheers |
Author: | btiffin [ Mon Jun 30, 2008 10:17 pm ] |
Post subject: | RE:Need a vim / perl guru |
Ok, this is what I ended up with. :%!perl -ne 'printf("\%06d\%s", $. * 10, substr($_, 6, -1) . "\n");' Cheers |