Hi Perlmonks.

How to get rid of extra spaces before the input separator \r\n ?
I have a flat file input separated by \r\n.,
Sample input :
FEATURE /group=" " /translation="MMSKLGVLLT ICLLLFPLTA VQLDGDQPAD LPALRT +QDIA TDHSPWFDPV KRCCSRYCYI CIPCCPN" /disulfide="9,19" /disulfide="13,24" /hydroxylation="10" /hydroxylation="11" /post_trans_mod="
For a few input lines, there are extra spaces before the \r\n, for eg :
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"
This cause trouble in my program even though I have check for extra spaces in my regex. This is part of my working program :
#!/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";
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.
What should I do since it's not possible for me to check the input files and remove the extra spaces.

Thank you in advanced.
Regards

Agustina


In reply to extra spaces before \r\n by agustina_s

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.