Reputation: 497
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!
Upvotes: 0
Views: 779
Reputation: 126772
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
}
Upvotes: 0
Reputation: 5069
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);
}
Upvotes: 1