Hi Wisma

You can try following set of code :
------------------
#!/usr/local/bin/perl -w

use warnings;


open (DATA , "data.txt") or die "can not open data.txt, $!";

open (DATA1, ">data1.txt") or die "can not open data1.txt, $!";

while(<DATA>){


        $string = $_;
 
        ($data1,$data2) = $string =~ /(Data     \w)\s+(.*)/;

        $data2 = join (",",split(/\s+/,$data2));

        $string = "$data1 = ($data2);\n";


print DATA1 $string;

}

close DATA;
close DATA1;
--------------------

Thanks
Sunita    

-----Original Message-----
From: wisma laili [mailto:wsmla...@yahoo.com] 
Sent: Thursday, March 17, 2011 2:54 PM
To: beginners@perl.org
Subject: Read and change the file

Hi Guys!

I am newbie in Perl.

I have problem in reading a file and change it to get some specific
output. For 
example : I want to read a file : filename.txt which contain  2 lines:
Data A 1 2 3 4 5  
Data B 6 7 8 9 10 
the name of the data and the values are tab separated.  my wish is to
change it 
into :Data A = (1,2,3,4,5); Data B = (6,7,8,9,10); 

Thanks in advanced for your kindly help!

Regards,
-student-


      

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to