Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: sorting headers in a file

by 2teez (Priest)
on Dec 13, 2013 at 08:03 UTC ( #1067000=note: print w/ replies, xml ) Need Help??


in reply to sorting headers in a file

Hi utpalmtbi,
I agree totally with the advice of usage of some kind of database as mentioned by hdb.
However, using your dataset one can get his/her dirty using perl hash and a kind of "modified" Schwartzian transform like so:

use warnings; use strict; my %hash; my $key; while (<DATA>) { next if /^\s+$/; if (/^>/) { $key = $_; } else { $hash{$key} = $_; } } print map { $_->[0], $hash{ $_->[0] }, $/ } sort { $a->[1] <=> $b->[1] } map { [ $_, /(\d+$)/ ] } keys %hash; __DATA__ >or3 agagatgatagat >or10 aacctttagtag >or1 gtatatatata >or2 tactacatgagg
NOTE:
I can't tell how this is do using a larger datasets..

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me


Comment on Re: sorting headers in a file
Download Code
Re^2: sorting headers in a file
by hdb (Parson) on Dec 13, 2013 at 08:23 UTC

    Your code relies on a number of implicit assumptions:

    • Using a hash implies that the ">or..." bits are unique. If two or more identical appear, your code would lose data.
    • You also assume that blank lines are of no significance.
    • If there is a multiline sequence, you will only store the last line.

      Your code relies on a number of implicit assumptions:...

      Assumptions that are savely ok considering the OP dataset.
      And that was why I said ..using your dataset.. i.e that of the OP in my previous reply, which I don't suppose have anything which follows "THE" assumptions, you stated. Except the OP has said otherwise to you privately.

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me

        I did not want to say that anything is wrong with your code. I only thought it useful to highlight the assumptions which you were aware of but probably not every reader of the thread. And I have no additional information about the question.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2014-07-13 23:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (252 votes), past polls