# Comparing Perspective Object - Never the same?

**URL:** <https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085>\
**Category:** Ignition\
**Tags:** perspective, ignition81\
**Created:** [November 15, 2021, 6:25pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085 "2021-11-15T18:25:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [November 15, 2021, 6:25pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085/1 "2021-11-15T18:25:50Z")

</div>

I thought it would be easy to compare two array object in Perspective. I was wrong.  
I had to implement an unnecessarily long script to compare them and return True, but this fails when attempt to do it with expression bindings.

Here an example. I have two label component with a custom array property that is literally a copy.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/7/9774d6820e5c563d6907c073fdd05e95f4962b3a.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/4485bac4bea93587de9617e29c2a74867a3e79cb.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/4/d4b3e071519f5b2a3dbfa2b93a71250d3789a6bc.png)

When I attempt to compare with

```auto
if({../Label.custom.array}={../Label_0.custom.array},'Same','Different')

```

I get that is different, why?  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/2/f2e96c78bb6554e184c4cc39c84950d188beef7c.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [November 15, 2021, 7:10pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085/2 "2021-11-15T19:10:50Z")

</div>

The expression equals operator is using ‘shallow’ quality; under the hood, for various reasons, this is ultimately becoming a simple identity check.

We could potentially make this smarter in the future, but it won’t help you much right now.  
In the short term, you can lean on Python a bit; use `runScript` to convert Perspective types to equivalent Python representation, then run your equality comparison on those:

```auto
def sanitize_tree(element):
    if hasattr(element, ' __iter__'):
        if hasattr(element, 'keys'):
            return dict((k, sanitize_tree(element[k])) for k in element.keys())
        else:
            return list(sanitize_tree(x) for x in element)
    return element

def deepEquals(left, right):
    return sanitize_tree(left) == sanitize_tree(right)

```

(see [this post](https://forum.inductiveautomation.com/t/function-to-convert-json-string-or-python-dict-into-objectwrapper/32861/16) for more on the `sanitize_tree` function)

Can be used basically the same as your existing:  
`runScript("utils.deepEquals", 0, {view.custom.left}, {view.custom.right})`  
 ![java_87kXhe](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/8/38877d5d1640bfab9d9b740c3aa88e031c27d2f3.png)  
 ![java_HTQddC](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/f/5f0389119276e8435c617922108098ad7d5151fe.png)  
 ![java_avv9fA](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/6/06a4ccdadb1b28c37d8b7858121b31a642c3262a.png)

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [November 15, 2021, 7:29pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085/3 "2021-11-15T19:29:07Z")

</div>

Oh, the shallow copy never can to my mind. That has sense  
Nice, yes I did a similar script but also comparing lengths.

Thanks for the knowledge.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 25, 2022, 4:20pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085/4 "2022-02-25T16:20:44Z")

</div>

In 8.1.16 comparison between arrays in expressions will work 'as expected':

> [@Nightly 8.1 Changelogs - 2022](https://forum.inductiveautomation.com/t/nightly-8-1-changelogs-2022/54636/29):
>
> Nightly Changelog: 8.1.16-b20220224 Infrastructure 5287: Reduce launcher attempts to comm with unnecessary gateways when starting up from a shortcut Reduce all launchers’ unnecessary network I/O when launching Designers, Vision Clients, or Perspective Workstation Sessions from shortcuts. 5281: Memory leak in perspective (due to jetty) Bumped Jetty version from 9.4.43.v20210629 to 9.4.45.v20220203 to fix a memory leak in Perspective due to a memory leak in Jetty’s web socket implementation …

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [February 25, 2022, 5:05pm UTC](https://forum.inductiveautomation.com/t/comparing-perspective-object-never-the-same/53085/5 "2022-02-25T17:05:22Z")

</div>

Great news, thanks for sharing the changelog!
