I hope the previous replies have solved the immediate problem for you, and you are getting stuff stored into your target file. Just a couple more comments about the code you posted:
- If a line from the input file does not contain any of the patterns that you are altering via "s///", that line will not be printed to the output file. Is this what you want?
- You are doing a lot of redundant typing. One of the nice things about Perl is that you can write scripts with an absolute minimum of repetitive lines of code.
If you actually want the output file to have the same number of lines as the input file (with some lines being edited), it's pretty short and simple:
use strict;
use warnings;
my $inp = "source.cbl";
my $out = "source.ada";
open INP, '<', $inp or die "Can't open $inp: $!";
open OUT, '>', $out or die "Can't open $out: $!";
while (<INP>) {
s/WORKING -STORAGE SECTION\./declare/;
s/PROGRAM -BEGIN\./begin/;
s/DISPLAY/PUT/;
s/ACCEPT/GET/;
s/PROGRAM -DONE\./END;/;
print OUT;
}
close INP; # no worries for closing input file
close OUT or die "Can't close $out: $!";
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.