如何在Powershell中比较关联数组?
我有两个关联数组,
$a = @{"k1"="v1"; "k2"=@{"k21"="v21"}}
$b = @{"k1"="v1"; "k2"=@{"k21"="v21"}}
我想知道有没有什么好的方法可以在不编写自己的函数的情况下进行比较?
I have two associative arrays
$a = @{"k1"="v1"; "k2"=@{"k21"="v21"}}
$b = @{"k1"="v1"; "k2"=@{"k21"="v21"}}
I was wondering is there any good way do the comparison without writing my own function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
除了编写一个函数来比较每个键的值(如果该值不是原始对象,则可能是递归的)之外,我不知道有什么方法。但是,PowerShell 中的关联数组只是 .NET 类型 (System.Collections.Hashtable)。您可能希望通过将
.NET
标记添加到您的问题中,向更广泛的 .NET 受众开放这个问题。There isn't a way that I know of except writing a function to compare each key's value (potentially recursive if the value is something other than a primitive object). However, associate arrays in PowerShell are just .NET types (System.Collections.Hashtable). You might want to open this question up to the broader .NET audience by adding the
.NET
tag to your question.为了完整起见,这里有一个用于比较哈希表的简单函数:
一些示例输出:
Just for completeness, here is a simple function for comparing hashtables:
Some example output: