Click here to get back home

Help: Reverse Letters

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Help: Reverse Letters Amy Lee 05-02-2008
Posted by Amy Lee on May 2, 2008, 12:04 pm
Please log in for more thread options
On Fri, 02 May 2008 15:51:34 +0000, Glenn Jackman wrote:

> At 2008-05-02 11:04AM, "Mirco Wahab" wrote:
>> Amy Lee wrote:
>> > while (<$FILE_IN>)
>> > {
>> > unless (/^>.*$/)
>> > {
>> > reverse $_;
>>
>> You need to reverse the order of the reverse
>> operator, before reversing the text:
>>
>> $_ =reverse;
>
> Also, the newline character will be reversed, so that should be removed
> first:
>
> while (<$FILE_IN>) {
> chomp;
> $_ = reverse unless /^>/;
> print "$_\n";
> }
Thank you very much. However, I still have a problem which I can't
understand well. What if my file content is
>seq1
ACGGTC
ACTG
>seq2
CGATCC
ACCTC
In fact, the sequence is
>seq1
ACGGTCACTG
>seq2
CGATCCACCTC

So if I use the above codes to do that, I can't acquire the correct
sequences. I hope I can process the file that I mention.

Thank you very much~

Amy Lee

Posted by Mirco Wahab on May 2, 2008, 12:21 pm
Please log in for more thread options
Amy Lee wrote:
> Thank you very much. However, I still have a problem which I can't
> understand well. What if my file content is
>> seq1
> ACGGTC
> ACTG
>> seq2
> CGATCC
> ACCTC
> In fact, the sequence is
>> seq1
> ACGGTCACTG
>> seq2
> CGATCCACCTC
>
> So if I use the above codes to do that, I can't acquire the correct
> sequences. I hope I can process the file that I mention.

Then you have to extract the sequences between
some bounds marker according to your problem.

You coult read the file w/different record
separator (eg. "\nseq") or create a regular
expression to extractz the sequences from
the file slurped into a buffer, like:

...
use warnings;
use strict;

# read the file into a buffer ($seq)
open my $fh, '<', 'sequence.dat' or die $!;
my $seq; do { local $/; $seq = <$fh> };
close $fh;

# extract sequence records
my $match = qrs;
while($seq =~ /$match/g) {
(my $sequence = $1) =~ tr/\n\r//d;
print "'$sequence'=>" . reverse($sequence) . "\n"
}
...


Regards

M.

Posted by Jürgen Exner on May 2, 2008, 12:58 pm
Please log in for more thread options
[reversing strings]
>What if my file content is
>>seq1
>ACGGTC
>ACTG
>>seq2
>CGATCC
>ACCTC
>In fact, the sequence is
>>seq1
>ACGGTCACTG
>>seq2
>CGATCCACCTC

You have a gift of stating requirements in a complex way that is
ambigious at best.

Are you saying that your data is split among many lines and should be
reversed across the whole file instead of line by line?

If that is the case then just slurp in the whole file into a single
string and reverse that string. Depending on if you want to preserve the
line breaks you may either have to chomp()/remove them or adjust the
leading/trailing line break of the whole file.

jue

Posted by Jürgen Exner on May 2, 2008, 5:57 pm
Please log in for more thread options
>Are you saying that your data is split among many lines and should be
>reversed across the whole file instead of line by line?
>
>If that is the case then just slurp in the whole file into a single
>string and reverse that string. Depending on if you want to preserve the
>line breaks you may either have to chomp()/remove them or adjust the
>leading/trailing line break of the whole file.

Oh, or of course you could just slurp the whole file into an array and
run reverse() twice, once on the array and once on each element of the
array. Details see the man page for reverse().

jue

Posted by Ben Bullock on May 2, 2008, 11:09 am
Please log in for more thread options
On Fri, 02 May 2008 22:53:08 +0800, Amy Lee wrote:

> reverse $_;

"Useless use of reverse in void context at ./usenet-2May2008-2.pl line 8."

As A. Sinan Unur told you previously, you should always

use warnings;
use strict;



Similar ThreadsPosted
Matching words and letters December 8, 2004, 11:33 pm
Lower casing letters of words July 15, 2005, 8:35 am
How to manipulate the cases of letters in a string? October 4, 2007, 7:47 pm
Getting Perl to ignore Letters when calculating numbers. March 30, 2005, 9:54 pm
regular expression consecutive numbers or letters November 1, 2006, 11:10 am
Perl Regex Question: how to translate only the leading letters of a line July 10, 2004, 4:52 pm
reverse dns August 18, 2006, 2:40 pm
FAQ 4.24 How do I reverse a string? May 12, 2005, 11:03 pm
FAQ 4.24 How do I reverse a string? January 21, 2005, 6:03 pm
FAQ 4.24 How do I reverse a string? July 28, 2005, 4:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap