in reply to Using perl interactively with VI

Update: Added "-w" and "use strict" and declared variables after rereading TomDLux's update.

Thanks for the hints-- I got something that works And learned a lot in the process. Which is always the goal. In case anyone ever is interested in calling a Perl script from VI, here's my solution (does several things besides those ennumerated in OP):

#!/usr/bin/perl -w use strict; my ($num,$v,$text,$qnum,$qtext,$stext,$spec,$x,$qspec); while (<>){ s/ \t/\t/g; s/9[0-9][0-9][0-9] \t/9999\t/g; s/9[0-9][0-9][0-9] /9999\t/g; if (/^[SCQD]/){ ($num,$v,$text) = split("\t"); chop ($num); $qnum=substr($_,0,index($_,".")); $qtext = substr($text,0,index($text,"?")+1); print "n03;coltxt=___\nn05TOTAL\nL $qnum\nttl$qnum. $qtext\nn1 +0TOTAL BASE\n"; } else { ($stext,$spec,$x) = split("[\t]"); chomp ($spec); $qspec = substr($spec,1,1); unless (/^$/){ print "n01$stext;c=c{$qnum}'$qspec'\n"} } } print "n03;coltxt=___\nn05TOTAL\n";

Basically, the key is to clear out some of the less predictable junk Before the if statement, and then use substr to control the more predictable junk in the scalar variables. And then if you want to add a line or two to the end of the section you're editing, print it in after the while loop and it adds the line(s) to the file.

Thanks again for the help.

Pax,

NovMonk

ps TomDLux: You're right about the chomp ($qspec); -- it's there because it Should be the last thing on the line, but wasn't always. I knew I didn't need anything after that field, so I named an extra one to make sure that junk didn't become part of $qspec.