Code:
$
$ cat -n f1
1 a,12,45,bn,c
2 a,16,46,bn1,c
3 a,18,47,bn2,c
4 a,12,47,bn3,c
5 a,11,49,bn4,c
6 a,19,79,bn8,c
$
$
$ ##
$ perl -lne 'chomp;
> if ($.%2 == 0) {
> $b = $.;
> push @x,$_;
> print "The pair of lines is now stored as first two elements of \@x";
> foreach $i (@x) {print "\t==> ",$i};
> print "Perform the calculations, print to file and reset the array";
> ## some calculations here...
> $file = "myfile_".$a."_".$b;
> print "Now writing to file: $file ";
> open (F, "> $file") or die "Cannot open $file for writing: $!";
> foreach $i (@x) {print F "\t==> ",$i};
> close (F) or die "Cannot close $file: $!";
> print "-"x60;
> @x=()}
> else { push @x,$_; $a=$. }' f1
The pair of lines is now stored as first two elements of @x
==> a,12,45,bn,c
==> a,16,46,bn1,c
Perform the calculations, print to file and reset the array
Now writing to file: myfile_1_2
------------------------------------------------------------
The pair of lines is now stored as first two elements of @x
==> a,18,47,bn2,c
==> a,12,47,bn3,c
Perform the calculations, print to file and reset the array
Now writing to file: myfile_3_4
------------------------------------------------------------
The pair of lines is now stored as first two elements of @x
==> a,11,49,bn4,c
==> a,19,79,bn8,c
Perform the calculations, print to file and reset the array
Now writing to file: myfile_5_6
------------------------------------------------------------
$
$ cat myfile_1_2
==> a,12,45,bn,c
==> a,16,46,bn1,c
$
$ cat myfile_3_4
==> a,18,47,bn2,c
==> a,12,47,bn3,c
$
$ cat myfile_5_6
==> a,11,49,bn4,c
==> a,19,79,bn8,c
$
$