agustina_s has asked for the wisdom of the Perl Monks concerning the following question:
For a few input lines, there are extra spaces before the \r\n, for eg :FEATURE /group=" " /translation="MMSKLGVLLT ICLLLFPLTA VQLDGDQPAD LPALRT +QDIA TDHSPWFDPV KRCCSRYCYI CIPCCPN" /disulfide="9,19" /disulfide="13,24" /hydroxylation="10" /hydroxylation="11" /post_trans_mod="
This cause trouble in my program even though I have check for extra spaces in my regex. This is part of my working program :Input: /disulfide="13,24"\r\n /hydroxylation="10" \r\n /hydroxylation="11"\r\n Output: Disulfide "13,24" Hydroxylation "10" Hydroxylation "11" Desired output: Disulfide "13,24" Hydroxylation "10" Hydroxylation "11"
I use flag in case the item consists of more than one line. The entry is always quoted, so I use the " to check whether it is already the end of the item.#!/usr/bin/perl -w use strict; #initialize all the variable, initialize flags to 0 and line to '' my $last; my $file1="$ARGV[0]"; my $result=">".$ARGV[1]; my $flag=0; my $templine=''; open(INFO1,$file1) or die "Can't open $file1.\n"; open(OUT,$result) or die "Can't open $result.\n"; foreach(<INFO1>) { if(/\s*\t*\s*\/(.*)=(.*)\s*\r/){ my $feature=$1; my $value=$2; if(($value !~ /" "/) && ($value !~ /""/)){ print OUT ucfirst($feature),"\t$value"; $last=chop($value); if($last eq "\""){ #if last element=" print OUT "\n"; $flag=0; } else { $flag=1; } } } elsif(/\s*(.*)\s*\r/ && $flag==1){ $templine=$1; print OUT " $1"; $last=chop($templine); if($last eq '"'){ print OUT "\n"; $flag=0; } } } close(INFO1) or die "Can't close $file1.\n"; close(OUT) or die "Can't open $result.\n";
Thank you in advanced.
Regards
Agustina
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: extra spaces before \r\n
by ajwans (Scribe) on Mar 06, 2002 at 03:03 UTC | |
by agustina_s (Sexton) on Mar 06, 2002 at 04:05 UTC | |
|
Re: extra spaces before \r\n
by trs80 (Priest) on Mar 06, 2002 at 04:15 UTC | |
|
Re: extra spaces before \r\n
by robsv (Curate) on Mar 06, 2002 at 17:14 UTC | |
|
Re: extra spaces before \r\n
by Juerd (Abbot) on Mar 06, 2002 at 12:15 UTC |