Tmms has asked for the wisdom of the Perl Monks concerning the following question:
Dear all
I have a text file and some of the lines contain a trailing asterisk (they are protein sequences and * stands for a stop codon). I was trying to write a short perl script to remove (substitute with empty string) them, but I got some results I found weird. Hopefully someone could help me.
I tried this code, but it does not work. The * are still there.
while(my $line = <$in>){ $line =~ s/\*$//; print $line; }
When I tried this code, it suddenly worked.
while(my $line = <$in>){ $line =~ s/\*\s$//; print $line; }
I think the previous code worked because every line contains a newline character (\n). But when I replace \s with \n the code stopped working. That made me confused and made me wonder these three things:
Thanks in advance.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Removing trailing asterisk from lines with regex
by AnomalousMonk (Archbishop) on Apr 14, 2017 at 22:16 UTC | |
|
Re: Removing trailing asterisk from lines with regex
by Anonymous Monk on Apr 14, 2017 at 21:03 UTC | |
|
Re: Removing trailing asterisk from lines with regex
by Anonymous Monk on Apr 14, 2017 at 21:17 UTC |