In a previous question ["Code golf: mean length of fasta sequences"][1], Eric asked for some solutions `to get the average length of the sequences in a fasta file`.

I tried to anwser this question using the following [Erlang][2] code:

    -module(golf).
    -export([test/0]).
    
    line([],{Sequences,Total}) ->  {Sequences,Total};
    line(">" ++ Rest,{Sequences,Total}) -> {Sequences+1,Total};
    line(L,{Sequences,Total}) -> {Sequences,Total+string:len(string:strip(L))}.
    
    scanLines(S,Sequences,Total)->
            case io:get_line(S,'') of
                eof -> {Sequences,Total};
                {error,_} ->{Sequences,Total};
                Line -> {S2,T2}=line(Line,{Sequences,Total}), scanLines(S,S2,T2)
            end  .
    
    test()->
        {Sequences,Total}=scanLines(standard_io,0,0),
        io:format("~p\n",[Total/(1.0*Sequences)]),
        halt().

**Compilation/Execution**:

    erlc golf.erl
    erl -noshell -s golf test < sequence.fasta
    563.16

this code seems to work fine for a small fasta file but it takes hours to parse **uniprot_sprot.fasta** (in fact , I pressed Ctr-C). Why ? I'm an Erlang newbie, can you improve this code ?

 [1]: /p/1758
 [2]: http://www.erlang.org
The answer is [here](http://stackoverflow.com/questions/3296855/average-length-of-the-sequences-in-a-fasta-file-can-you-improve-this-erlang-co/3304288#3304288)