ARTICLES

count_x.erl
Written by Raimo, 26 Apr 2010

Count the number of x's in a file

-module(count_x).
-author('joe@cslab.ericssons.se').

%% count the number of x's in a file

-export([file/1]).

file(F) ->
    lists:foldl(fun($x,N) -> N + 1;
		   (_, N) -> N
	        end,
		0, 
		binary_to_list(element(2, file:read_file(F)))).
> count_x:file("count_x.erl").
4

Browse articles

Powered by Erlang Web