Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Sorting strings

by mreece (Friar)
on Jan 26, 2007 at 02:26 UTC ( #596661=note: print w/replies, xml ) Need Help??


in reply to Sorting strings

you can set the input record separator to \n\n to read the paragraph format you have there. then the default sort will work, if the prefix is the same on every line.
#!perl use strict; use warnings; my @data; { local $/ = "\n\n"; @data = <DATA>; } my @sorted = sort @data; print @sorted; __DATA__ >ENSP00000314624 GCACAATGGTAGAGGCAGATCATCC >ENSP00000347089 ATGGATTGCTGTGCCTCTCGAGGCT >ENSP00000301587 TGACCCACTTCCGTTACTTGCTGCG
produces
>ENSP00000301587
TGACCCACTTCCGTTACTTGCTGCG

>ENSP00000314624
GCACAATGGTAGAGGCAGATCATCC

>ENSP00000347089
ATGGATTGCTGTGCCTCTCGAGGCT

Replies are listed 'Best First'.
Re^2: Sorting strings
by uvnew (Acolyte) on Jan 26, 2007 at 12:55 UTC
    Thanks a lot, that works perfectly! Can you recommend a good tutorial for regular expressions? I think I really need that... Cheers, uv

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://596661]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2021-02-27 12:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?