ERlang - 尝试查找列表成分的长度
猜猜已经晚了,我是一个初学者,只需要一点帮助..
我试图找到列表的长度..但不是列表本身,而是其中值的长度..
我采取类似的东西:
Other = [<<"366">>,0,
<<1>>,
<<"344">>,<<"Really"
<<1>>,
<<"989">>,<<"NotReally">>
<<1>>,
<<"345">>,4,
<<1>>,
<<"155">>,"209.191"]
我确实想首先将 Other 转换为其 RAW 组成二进制文件
示例:
Other = [<<3>>,<<4>>,<<7>>,<<56>>,<<45>>,<<56>>...]
当然,这是原始 Other 的示例(不是正确的转换值)。这样里面的所有值都是最基本的二进制数据。
然后我可以简单地迭代计算每个 <<_>>并确定总消息长度。
希望我足够清楚能够找到解决方案。
感谢大家的帮助,GN
guess its getting late, and Im a beginner, just need a little help..
Im trying to find the length of a list.. BUT NOT of the lists themselves, rather the length of the values within..
I take something like:
Other = [<<"366">>,0,
<<1>>,
<<"344">>,<<"Really"
<<1>>,
<<"989">>,<<"NotReally">>
<<1>>,
<<"345">>,4,
<<1>>,
<<"155">>,"209.191"]
I would really want to first convert Other into its RAW constituent binary
Example:
Other = [<<3>>,<<4>>,<<7>>,<<56>>,<<45>>,<<56>>...]
This, of course, is an example of way the original Other would look like(Not right conversion values). So that all of the values in there are there most basic binary data.
Then I could simply iterate through counting each <<_>> and determining the total message length.
Hope I was clear enough to find a solution.
Thanks all for the help, GN
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iolist_size/1
就是你寻找。PS:为什么你的示例数据有这一多余特征? ;-)
iolist_size/1
is what you are looking for.P.S.: Why your example data have this one surplus character? ;-)
如果你想做的只是找到整个结构的长度,我会尝试这样的事情:
如果你真的想构建结构的平面版本,那么 erlang:list_to_binary 可以让你非常接近你需要的东西,然后就调用 size 即可。 (实际上,这可能比我的第一次尝试更好。)
If all you're trying to do is find the length of the entire structure, I'd try something like this:
If you really want to build a flat version of your structure, then erlang:list_to_binary gets you pretty close to what you need, then just call size on that. (Actually, this may be better than my first attempt.)