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:[email protected]]
Sent: Thursday, March 17, 2011 2:54 PM
To: [email protected]
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: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/