I'm trying to use a regular expression to search for values stored in hash that begin with three letters: "Hox." This is driving me crazy and I figure I must be overlooking something very simple. I've got my script working so that everything works except my if statement. Can you wise monks help me see what I can't?
#!/usr/bin/perl -w # Open Tab-delimited file, extract and display HOX gene info #FILE HANDLING open INPUT,"<MOUSE_TF1.txt"; open OUTPUT,">HOX_GENE_TF.txt"; # # MAIN 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>){ $line = $_; chop($line); # split line by tab character @Gene_Info = split("\t",$line); # Defines fields as scalars $Ensembl_Gene_ID = $Gene_Info[0]; $Chromosome_Name = $Gene_Info[1]; $Gene_Start = $Gene_Info[2]; $Gene_End = $Gene_Info[3]; $Chr_Strand = $Gene_Info[4]; $Gene_Symbol = $Gene_Info[5]; # Create hashes to store table values and associate with key $chrs{$Ensembl_Gene_ID} = $Chromosome_Name; $starts{$Ensembl_Gene_ID} = $Gene_Start; $ends{$Ensembl_Gene_ID} = $Gene_End; $symbols{$Ensembl_Gene_ID} = $Gene_Symbol; $strands{$Ensembl_Gene_ID} = $Chr_Strand; } close INPUT; # select Gene Symbols belonging to "Hox" family and print foreach $key (keys %symbols) { if ($Gene_Symbol =~ /Hox/) { print OUTPUT $key,"\t"; print OUTPUT $symbols{$key},"\t"; print OUTPUT $chrs{$key},"\t"; print OUTPUT $starts{$key},"\t"; print OUTPUT $ends{$key},"\t"; print OUTPUT $strands{$key},"\n"; } } close INPUT; close OUTPUT; #end

In reply to 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.