简体   繁体   English

输出ETS表Erlang的内容

[英]Output the contents of an ETS Table Erlang

I am new to the world of Erlang so I am trying to experiment with it. 我是Erlang世界的新手,所以我尝试尝试一下。

I have an ETS table that is called numbers. 我有一个称为数字的ETS表。

ets:new(numbers,[ordered_set,named_table])

It has the format [{Name,Number},{Name,Number}] etc. 它的格式为[{Name,Number},{Name,Number}]等。

I am wondering is there a way to output the contents of the whole the ets table? 我想知道是否有一种方法可以输出整个ets表的内容?

Tl;dr 文艺青年最爱的

you can use 您可以使用

ets:match_object(Tab, {'$0', '$1'}).

Where Tab is your table name, ie numbers . 其中Tab是您的表格名称,即numbers

In depth: 深入:

The second argument is a match pattern , leaving "free variables" '$0' and '$1' . 第二个参数是匹配模式 ,保留“自由变量” '$0''$1'

Let's say you inserted: 假设您插入了:

> ets:insert(Tab, [{age, 45}, {length, 10}, {height, 45}]). 

You could get out all {_, 45} tuples with: 您可以使用以下命令清除所有{_, 45}元组:

> 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. 通过使所有(在本例中为2)元组参数变为自由变量,您将匹配表中的所有内容。

I highly recommend reading Learn You Some Erlang for more info! 我强烈建议阅读“ 学习一些Erlang”了解更多信息!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM