<html><body><div style="color:#000; background-color:#fff; font-family:Courier New, courier, monaco, monospace, sans-serif;font-size:10pt"><div><span>I am learning Erlang, and I must be doing something wrong here; please correct me! Thanks.<br></span></div><div><br><span></span></div><div><span>avinash@bhakti:~$ erl<br>Erlang R14B02 (erts-5.8.3) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]<br><br>Eshell V5.8.3 (abort with ^G)<br>1> T=ets:new(test, [set]).<br>16400<br>2> ets:insert(T, {"erlang", 1}).<br>true<br>3> ets:insert(T, {"ericsson", 2}).<br>true<br>4> ets:insert(T, {"erring", 3}). <br>true<br>5> <br>5> ets:insert(T, {"ejection", 4}).<br>true<br>6> ets:insert(T, {"emersion", 5}).<br>true<br>7> ets:select(T, [{{'$1', '_'}, [], ['$$']}]).<br>[["erring"],<br> ["emersion"],<br> ["ericsson"],<br> ["erlang"],<br> ["ejection"]]<br>8>
ets:select(T, [{{'$1', '_'}, [{'==', '$1', "er"++'_'}], ['$$']}]).<br>[]<br>9> ets:select(T, [{{'$1', '_'}, [{'=:=', '$1', "er"++'_'}], ['$$']}]).<br>[]<br>10> ets:select(T, [{{'$1', '_'}, [{'=', '$1', "er"++'_'}], ['$$']}]). <br>** exception error: bad argument<br> in function ets:select/2<br> called as ets:select(16400,<br> [{{'$1','_'},[{'=','$1',[101,114|'_']}],['$$']}])<br>11> <br></span></div><div><span><br></span></div><div><br></div> <div style="font-family: Courier New, courier, monaco, monospace, sans-serif; font-size: 10pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr"> <font size="2" face="Arial"> <hr size="1"> <b><span
style="font-weight:bold;">From:</span></b> Ulf Wiger <ulf@feuerlabs.com><br> <b><span style="font-weight: bold;">To:</span></b> Martin Dimitrov <mrtndimitrov@gmail.com> <br><b><span style="font-weight: bold;">Cc:</span></b> Erlang Questions <erlang-questions@erlang.org> <br> <b><span style="font-weight: bold;">Sent:</span></b> Thursday, 9 February 2012 9:18 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [erlang-questions] searching in an ETS table for substring<br> </font> </div> <br><br>If the key is a list (not a binary), you can use the pattern "foo" ++ '_'.<br><br>There is no equivalent syntax for binaries.<br><br>If the table is an ordered set, this search will be efficient, since it will use the bound prefix to narrow the search.<br><br>BR,<br>Ulf<br><br>On 9 Feb 2012, at 16:37, Martin Dimitrov wrote:<br><br>> Hello,<br>> <br>> Is it possible to search in an ETS table for a key that starts
with<br>> certain characters?<br>> Something equivalent to:<br>> <br>> SELECT * FROM table WHERE name LIKE 'some%'<br>> <br>> I read the documentation for select/2 and it says we can use as guards<br>> functions as is_* and the like.<br>> <br>> Best regards,<br>> <br>> Martin<br>> _______________________________________________<br>> erlang-questions mailing list<br>> <a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>> <a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br>_______________________________________________<br>erlang-questions mailing list<br><a ymailto="mailto:erlang-questions@erlang.org" href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br><a href="http://erlang.org/mailman/listinfo/erlang-questions"
target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br><br><br> </div> </div> </div></body></html>