I am still working on some text editing utilities, written in Perl which are able to be called from VI thus:
:1,105! Perlscript
My aim is to convert a text file I’m editing in VI into code that can be read by an ancient market research software called Quantum Without doing a lot of manual editing. (Yes, I am ashamed to admit I am not a real programmer at all, but perhaps if I learn enough doing this, I might grow up to be one someday.)
I’m using split to break the lines up into fields I can rearrange into what I need, but I’ve got “junk” in some of my fields. My questions:
1. Is there a function that allows one to take the first character off a scalar variable in the same way you’d take the last character off with chop ? For example, can I make the string -3 become just 3?
2. Is it possible to look at a scalar variable containing a string, chop off all text after, say, a question mark, and make that be the new value of the scalar, thus:
$qtext = “question text? Lots of junk after that I don’t need”
becomes
$qtext = “question text?”
It might help to see what script I'm trying to incorporate the above ideas into, so here it is:
#!/usr/bin/perl while (<>){ if (/^[SCQD]/){ ($qnum,$v,$qtext) = split("\t"); chop ($qnum); print "L $qnum\nttl$qnum. $qtext\nn10TOTAL BASE\n"; } else { ($stext,$qspec,$x) = split("[\t]"); chomp ($qspec); unless (/^$/){ print "n01$stext;c=c{$qnum}'$qspec'\n"} } }
Am I just trying to do too much here, editing line by line? Is there a better but still simple way to structure this?
Any nudges in the right direction appreciated.
NovMonk
Edit by tye to remove lots of trailing space in CODE
In reply to Using perl interactively with VI by NovMonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |