in reply to sorting headers in a file

one of ways to go:
$/ = '>or'; sub{$h{$1} = $2 if /(\d+)\n\n(\w+)/}->() foreach <DATA>; foreach (sort { $a<=>$b } keys %h){ print ">or$_\n\n$h{$_}\n\n"; } __DATA__ >or3 agagatgatagat >or10 aacctttagtag >or1 gtatatatata >or2 tactacatgagg
output
>or1 gtatatatata >or2 tactacatgagg >or3 agagatgatagat >or10 aacctttagtag

Replies are listed 'Best First'.
Re^2: sorting headers in a file
by hdb (Monsignor) on Dec 13, 2013 at 08:34 UTC

    I would write

    sub{$h{$1} = $2 if /(\d+)\n\n(\w+)/}->() foreach <DATA>;
    as
    /(\d+)\n+(\w+)/ and $h{$1} = $2 for <DATA>;

    which I think is more readible. The modification of the regex makes it a little more robust relative to the formatting of the data. You would also lose data if there are duplicate ">or..." bits and multiline sequences.

      thanks for corrections
      your code is beautiful
      gotta remember that construction