Search code examples
perlprintingprintfblock

Printing in blocks


I want to print the results in two blocks (idA and idB are various genes, $level goes from 1 to 3)

open(TGFILE, "> $ofile2") || die("### ERROR ### Cannot open dot file: $ofile2\n");
printf TGFILE "'%s'\t'%s'\n", $idA, $idB;
printf TGFILE "//NODECLASS\t'%s'\t'level'\t'$level'\n", $idA;

it gives me the results of genes interacting in a file:

'SNRNP200'  'SNRNP200'
//NODECLASS 'SNRNP200'  'level' '1'
'SNRNP200'  'RNU6ATAC'
//NODECLASS 'RNU6ATAC'  'level' '1'
'RNU6ATAC'  'YBX1'
//NODECLASS 'YBX1'  'level' '1'
...
...

but I want to have it like this in two blocks in the output file because there are thousands of genes and can't do it manually:

'SNRNP200'  'SNRNP200'
'SNRNP200'  'RNU6ATAC'
'RNU6ATAC'  'YBX1'
//NODECLASS 'SNRNP200'  'level' '1'
//NODECLASS 'RNU6ATAC'  'level' '1'
//NODECLASS 'YBX1'  'level' '1'

Solution

  • You could print them to two different files, and combine these two files later.