logo       

Re: if loop problem: msg#00419

perl-beginners

Subject: Re: if loop problem

On Fri, Jul 31, 2009 at 10:19, <98447122@xxxxxxxxxxxxxx> wrote:
> This is what the file actually looks like. All fileds are
> separated by tabs
snip

The following script has visibly correct data and works. This points
to your data being the problem. Try this one-liner to see what you
data really looks like:

perl -nle 'print join ", ", map { "[$_]" } split /\t/' datafile

#!/usr/bin/perl

use strict;
use warnings;

my $fakefile = <<EOF;
HMU00030\t2522\t4840\t\tDNA gyrase subunit B
HMU00040\t4841\t5083\t\tputative membrane protein
HMU00050\t5080\t5739\tc\tputative periplasmic C39-family peptidase
HMU00060\t5739\t6549\tc\tputative inner membrane protein
EOF

open my $fh, "<", \$fakefile
or die "could note create a fake file: $!";

while(<$fh>){
my ($Gene, $Start, $Stop, $Strand, $Product) = split /\t/;
if ($Strand eq "c"){
print "$Gene\t-\t$Start\t$Stop\t$Product\n";
} else {
print "$Gene\t+\t$Start\t$Stop\t$Product\n";
}
}

--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

--
To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
For additional commands, e-mail: beginners-help@xxxxxxxx
http://learn.perl.org/


Google Custom Search

News | Mail Home | sitemap | FAQ | advertise