The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

soostibi (11) [Avatar] Offline
#1
I don't understand why this is not evaluated as true:
[6] PS I:>(1,2),3 -contains (1,2)
False

And if:
[7] PS I:>1,2,3 -eq 2
2

Why
[8] PS I:>(1,2),3 -eq (1,2)
does not give 1,2 back to me?
brucepay (155) [Avatar] Offline
#2
Re: -eq and -contains with arrays
The -eq operator is comparing array references, not array contents. If the same array instance (as opposed to a different instance containing the same values) is used on the left and right sides, then it will work:

PS (13) > $x = (1,2)
PS (14) > 1,$x,3 -eq $x
1
2
PS (15) > 1,$x,2,$x -eq $x
1
2
1
2

-bruce
soostibi (11) [Avatar] Offline
#3
Re: -eq and -contains with arrays
Thanks Bruce!
Doesn't it make sense to create such an additional -eq-like and -contains-like operator that works against array contents? Maybe in PS v2.0? I'm not a developer, so I don't know if there is a real need for that, but it seems very logical for me...