Here is my problem.. i have 2 files (file1, file2).. i have wrote the last two lines and first 4 lines of "file2" into two different variables .. say..
my $firstrec = `head -4 $file2`;
my $lastrec = `tail -2 $file2`;
and i write the rest of the file2 to a tmpfile and cat it with head -4 | tail -2 of file1 ...
now i need to add the first line and last lines to this tmpfile...
I'm confused, why are you using perl if you are shelling out to the operating system? Unless file2 is gigantic, read it all into an array. Then use the array to do what you want.
open (FILE2, 'file2');
my @array = <FILE2>;
close FILE2;
my @first4 = @array[0..3];
my @last2 = @array[-2,-1];
my @rest_of_lines = @array[4..$#array-2];
Of course all those temp arrays are probably not necessary, I just use them to illustrate the array slice syntax you can use to achieve this using perl.
But I do not understand this requirement so I can't advise further:
now i need to add the first line and last lines to this tmpfile...