0

I am trying to split the contents of a txt file to extract relevant information using perl, but I can't seem to format my split statement correctly. A line of the file looks like this:

1.8|8|28|98|1pter-p22.1|SAI1, MTS1, TFS1|C|Suppression of anchorage independence-1 (malignant transformation suppression-1)|154280|S, H|||4(Tfs1)|

and my split statement looks like this:

my $file;
my $important;
my $line;
my @info;
foreach $line (@OMIMFile) {
my ($noSystem, $month, $day, $year, $cytoLoc, $geneSymb
    , $geneStat, $title, $mimNo, $method, $comment, $disorder
    , $mousCorr, $ref) = split ("|", $line);
    $important = $geneSymb.":".$disorder;
    push @info, $important if ($geneStat =~ /C/i);
}

I would like each line of @info to be the combination of $geneSymb and $disorder separated by a colon, but currently a print of @info returns nothing and $important returns an output like this:

|:||:|2:7|:|1:||:|0:||:|0:|1:85:|7:|9:01:37:93:93:93:92:71: .....

Where am I going wrong here?

Thanks in advance!

1
  • 3
    You forgot to escape pipe: \|. Also it should be a regex: /\|/. Commented Feb 7, 2014 at 13:38

2 Answers 2

1

Here is a fix.

Some of your variables was not local.

my $file;
my @info;
foreach my $line (@OMIMFile) {
my ($noSystem, $month, $day, $year, $cytoLoc, $geneSymb
    , $geneStat, $title, $mimNo, $method, $comment, $disorder
    , $mousCorr, $ref) = split (/\|/, $line);
    my $important = $geneSymb.":".$disorder;
    push @info, $important if ($geneStat =~ /C/i);
}
Sign up to request clarification or add additional context in comments.

Comments

0

This would be a lot neater using hash slices:

my @fields = qw/ noSystem month day year cytoLoc geneSymb geneStat title mimNo method comment disorder mousCorr ref /;
my @info;

for (@OMIMFile) {
  my %line;
  @line{@fields} = split /\|/;
  my $important = join ':', @line{ qw/ geneSymb disorder / };
  push @info, $important if $line{geneStat} =~ /C/i
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.