On Tue, 7 Dec 2004, Frank Westfield wrote:

> Sorry if what I said was not clear enough.
> 
> I have a string of between 16 and 24 consecutive characters - no 
> spaces or other non-alphanumeric characters which split can work on 
> (as I understand split).  I need to process each character and reorder 
> the resulting manipulated characters into a new string.
> 
> This is an existing perl application which I did not design so unless 
> I redesign the whole thing I cannot change the process.  (If I did it 
> would not be in Perl I think)  Hence the wording of my original 
> question.
> 
> In Java I simply create a String Object and call the toArray method 
> and its all done - a nice array full of characters.  I am surprised 
> that Perl with strong manipulation reputation doesn't have similar 
> functionality.
 
It does, but it doesn't work like Java, so don't think like Java. 

What you're describing is typically a one line statement in Perl, but 
you still haven't clearly spelled out what you're doing, so I can't 
really describe that statement though. Typically though, this would be 
done in a substitution statement, like so:

  s/remove this/add that/

or to turn "resequence a c t g" into "new sequence g c a t":

  s/resequence (a) (c) (t) (g)/new sequence $4 $2 $1 $3/ 

You can also do this sort of thing with split, but in general, Perl 
programmers don't go about problems like this by first decomposing the 
string into discrete characters -- as you're trying to go -- even though 
in the background that is of course how the regular expressions engine 
works and how various data types are represented. But so what, this is a 
higher level langauage than that, so you don't have to work about it.


So, let's get concrete. What do these strings look like? How do you want 
to transform them? What do you want them to look like in the end?



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to