I'm trying to learn perl on my own as part of a side projest through work. I have come up with a perl script that is nearly perfect and will save me TONS of time. Here's what I want to happen:
___DATA.FILE______
- Here is a line
- This is a line too
- You get the idea
___DESIRED.OUTPUT__
[one tab] 'HERE IS A LINE'/
'THIS IS A LINE TOO'/
'YOU GET THE IDEA'<---here's the problem, the current code places a '/', but I don't need one on the last line.
The code I have is:
This script works beautifully except for the '/' on the last line. I also have some pattern switching going on after the regex line i.e. $instr~ s/cat/dog/g; I'm not sure how I can get that last '/' of of that line. Any suggestions would be great. Many thanks in advance-
Joe
___DATA.FILE______
- Here is a line
- This is a line too
- You get the idea
___DESIRED.OUTPUT__
[one tab] 'HERE IS A LINE'/
'THIS IS A LINE TOO'/
'YOU GET THE IDEA'<---here's the problem, the current code places a '/', but I don't need one on the last line.
The code I have is:
Code:
open(TXT,"ARGV[0]") || die "Cannot open the data file";
$instr = do{local $/; <TXT> };
close(TXT);
chomp($instr);
$instr =~ s/\-\s+([^\n]+)/\t\U'$1\'\//g;
chop($instr);
open(TXT,">ARGV[1]") || die "Cannot open the formatted file";
print TXT $instr;
close(TXT);
Joe