If I'm not mistaken, your are trying to print out lines in which the "symbol" starts with the string "Hox". If that is the case, I see no need for building up a hash at all; just process the lines as you read them in. If you really want to re-order the columns, then this might be a simpler way to do things (UNTESTED):
use strict; use warnings; open INPUT,"<MOUSE_TF1.txt" or die "can not open MOUSE_TF1.txt: $!"; open OUTPUT,">HOX_GENE_TF.txt" or die "can not open HOX_GENE_TF.txt: $ +!"; print OUTPUT "MOUSE TRANSCRIPTION FACTORS IN THE HOX GENE FAMILY\n\n\n +"; print OUTPUT "ENSEMBL GENE ID \tSYMBOL \tCHR\tSTART\t\tEND\t\tSTRAND\n +"; while (<INPUT>){ chomp; my ($id, $cname, $start, $end, $strand, $sym) = split /\t/; # select Gene Symbols belonging to "Hox" family and print if ($Sym =~ /^Hox/) { print join("\t", $id, $sym, $cname, $start, $e +nd, $strand), "\n" } } close INPUT; close OUTPUT;

If you are willing to preserve the column order from the input, this simplifies even further to:

use strict; use warnings; open INPUT,"<MOUSE_TF1.txt" or die "can not open MOUSE_TF1.txt: $!"; open OUTPUT,">HOX_GENE_TF.txt" or die "can not open HOX_GENE_TF.txt: $ +!"; print OUTPUT "MOUSE TRANSCRIPTION FACTORS IN THE HOX GENE FAMILY\n\n\n +"; print OUTPUT "ENSEMBL GENE ID \tCHR\tSTART\t\tEND\t\tSTRAND\tSYMBOL\n" +; while (<INPUT>){ chomp; my @items = split /\t/; # select Gene Symbols belonging to "Hox" family and print if ($items[5] =~ /^Hox/) { print "$_\n" } } close INPUT; close OUTPUT;

In reply to Re: If Statements and Regular Expressions by toolic
in thread If Statements and Regular Expressions by TempAcolyte

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.