> > Dear all. > > I have a tab delimited file as follow: > > V name p > 1.0 AAA 0.001 > 0.9 BBB 0.003 > 0.8 CCC 0.004 > ..... > > I need to convert the file into following format: > { labels = > ( > {v="1.0"; name = "AAA"; p = "0.001"; }, > {v="0.9"; name = "BBB"; p = "0.003";}, > {v="0.8"; name = "CCC"; p = "0.004";} > ); > }
Hi, Here is my little contribution. Im a newbie myself... I may not have understood your question completely, but here is some code that writes to a file in the format that you have described above. thx, radhika ========================================= #!/usr/bin/perl -w use strict; use diagnostics; #{v="1.0"; name = "AAA"; p = "0.001"; }, #{v="0.9"; name = "BBB"; p = "0.003";}, #{v="0.8"; name = "CCC"; p = "0.004";} my $file = "data.txt"; #file read from my $outfile = "data_out.txt"; #file to write to my @header = ("v", "name", "p"); open(DATA, "<$file") or die "Cannot Open - $!\n"; open(OUT, ">$outfile") or die "$!\n"; print OUT "labels=\n"; print OUT "\(\n"; while ( <DATA> ) { #while loop to read first line only if( $_ =~ /(\d+)\s+(\w+)\s+(\d+)/ ) { print OUT "\{$header[0]=\"$1\"\; "; print OUT "$header[1]=\"$2\"\; "; print OUT "$header[2]=\"$3\"\; \}\n"; } } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>