#!/usr/bin/env perl -i
use strict;
use warnings;
while (<>) {
print;
print "VALUE=KEY\n" if $. == 3;
$. = 0 if eof;
}
I suggest you read "perlrun - how to execute the Perl interpreter".
Amongst other things, this will tell you about the Command Switches: perhaps lack of knowledge in this area is why you're coding your script the way you are.
I put the above code in pm_1076103.pl and created three *.doc files:
$ ls -al *.doc
-rw-r--r-- 1 ken staff 52 26 Feb 03:20 pm_1076103_1.doc
-rw-r--r-- 1 ken staff 52 26 Feb 03:22 pm_1076103_2.doc
-rw-r--r-- 1 ken staff 52 26 Feb 03:22 pm_1076103_3.doc
$ cat pm_1076103_1.doc
Doc 1 Line 1
Doc 1 Line 2
Doc 1 Line 3
Doc 1 Line 4
$ cat pm_1076103_2.doc
Doc 2 Line 1
Doc 2 Line 2
Doc 2 Line 3
Doc 2 Line 4
$ cat pm_1076103_3.doc
Doc 3 Line 1
Doc 3 Line 2
Doc 3 Line 3
Doc 3 Line 4
I then ran the script like this:
$ pm_1076103.pl *.doc
Here's what the *.doc files now look like:
$ cat pm_1076103_1.doc
Doc 1 Line 1
Doc 1 Line 2
Doc 1 Line 3
VALUE=KEY
Doc 1 Line 4
$ cat pm_1076103_2.doc
Doc 2 Line 1
Doc 2 Line 2
Doc 2 Line 3
VALUE=KEY
Doc 2 Line 4
$ cat pm_1076103_3.doc
Doc 3 Line 1
Doc 3 Line 2
Doc 3 Line 3
VALUE=KEY
Doc 3 Line 4
|