Search in record list

Ola Andersson A (AL/EAB) <>
Fri Mar 17 15:31:40 CET 2006


Isn't that like cheating a bit?
Using the fact that records are tuples.
 
Alternative:

F = fun(Rec) when Rec#process_info.pid == Pid -> false;
       (Rec) -> true
    end,
[Arec | _] = lists:dropwhile(F, List).

There are probably about a hundred more efficient ways to do it, but
anyway.
/OLA.
 
> -----Original Message-----
> From:  
> [mailto:] On Behalf Of Bengt Kleberg
> Sent: den 17 mars 2006 15:12
> To: 
> Subject: Re: Search in record list
> 
> On 2006-03-17 14:59, Inswitch Solutions wrote:
> >  
> > Hi,
> >  
> > Does someone know an easy way to search by a field of a record on a 
> > list of records?
> >  
> > For example:
> >  [ {process_info, {Id, Pid, QueueLength}}...]
> >  
> > Find the record with Pid element in the list.
> 
> is this what you want:
> lists:keysearch(Pid, #process_info.pid, List).
> 
> 
> bengt
> 



More information about the erlang-questions mailing list