in reply to If Statements and Regular Expressions
There is a pile of stuff that can be tidied up there. First off, always use strictures (use strict; use warnings;).
Use the three parameter version of open and check the result. Use lexical file handles:
open my $inFile, '<', "MOUSE_TF1.txt" or die "Failed to open MOUSE_TF1 +.txt: $!";
Instead of using "parallel" data structures that have to be handled piecemeal, group common data using a hash:
use warnings; use strict; open my $inFile, '<', "MOUSE_TF1.txt" or die "Failed to open MOUSE_TF1 +.txt: $!"; my %families; my @fields = qw(chr start end symbol strand); while (<$inFile>) { my $line = $_; chomp ($line); my @Gene_Info = split "\t", $line; my $id = shift @Gene_Info; @{$families{$id}}{@fields} = @Gene_Info; } close $inFile; # select Gene Symbols belonging to "Hox" family and print foreach my $key (keys %families) { if ($key =~ /Hox/) { print join ("\t", $key, @{$families{$key}}{@fields}), "\n"; } }
untested
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: If Statements and Regular Expressions
by JavaFan (Canon) on Oct 01, 2008 at 00:12 UTC | |
by GrandFather (Saint) on Oct 01, 2008 at 00:27 UTC | |
by JavaFan (Canon) on Oct 01, 2008 at 00:56 UTC |