I am new to the world of Erlang so I am trying to experiment with it.
I have an ETS table that is called numbers.
ets:new(numbers,[ordered_set,named_table])
It has the format [{Name,Number},{Name,Number}] etc.
I am wondering is there a way to output the contents of the whole the ets table?
you can use
ets:match_object(Tab, {'$0', '$1'}).
Where Tab
is your table name, ie numbers
.
The second argument is a match pattern , leaving "free variables" '$0'
and '$1'
.
Let's say you inserted:
> ets:insert(Tab, [{age, 45}, {length, 10}, {height, 45}]).
You could get out all {_, 45}
tuples with:
> ets:match_object(Tab, {'$0', 45}).
[{age, 45}, {height, 45}]
By making all (in this case, 2) of the tuple parameters free variables, you will match everything in the table.
I highly recommend reading Learn You Some Erlang for more info!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.