I have a file of contents:
-----------
1 6
2 7
3 8
4 9
5 10
----------
I want a file with content:

1 2 3 4 5
6 7 8 9 10

--------
I have written a few lines of following code but it does not work as expected  :

-------------------------------------------
#!/usr/bin/perl
use v5.10;
use strict;
use warnings;

open(FILE, "numbers.txt") or die "can not open file . $!\n";
open(FILE1, ">sumfile.txt") or die "can not open file . $!\n";

my @lines = <FILE>;
chomp @lines;

my $c=0;
while ($c <= $#lines){
      if ($lines[$c] =~ /(\w+)\s+(\w+)/){
           print FILE1 "$1\n";
           print FILE1 "$2";
      
      }

$c++;
       }
       
       close FILE;
       close FILE1;
--------------------------

Please guide me .
                                          

Reply via email to