Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Test scalar refs (not values) in deeply nested structure

by syphilis (Archbishop)
on Jul 24, 2020 at 03:51 UTC ( [id://11119732]=note: print w/replies, xml ) Need Help??


in reply to Test scalar refs (not values) in deeply nested structure

Hi Rolf,

So ... you have:
my ($pos1,$pos2)=("a","a");
and you want a test that will report that \$pos1 and \$pos2 are "different".
I think a simple cmp_ok(\$pos1, 'eq', \$pos2, "should fail"); will fail.
The bit I haven't quite grasped is the circumstances under which \$pos1 and \$pos2 should be considered the same.
What values do you assign to $pos1 and $pos2 such that this test should report that \$pos1 and \$pos2 are "the same" ?

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: Test scalar refs (not values) in deeply nested structure
by perlfan (Vicar) on Jul 24, 2020 at 04:46 UTC
    >The bit I haven't quite grasped is the circumstances under which \$pos1 and \$pos2 should be considered the same.

    I am also confused since your example is not nested at all, i.e., I don't think the scalar reference itself is considered nested since you're pointing to two different memory structures (addresses). Do you have an actual nested data structure, LanX?

Re^2: Test scalar refs (not values) in deeply nested structure
by LanX (Saint) on Jul 24, 2020 at 06:23 UTC
    > The bit I haven't quite grasped is the circumstances under which \$pos1 and \$pos2 should be considered the same.

    Never, it's a false positive.

    (Or to be more precise only if both are aliases, hence \$pos1 == \$pos2 , but which can't happen in my use case )

    They are not nested in the OP because it's the easiest possible demo.

    See here Re: Test scalar refs (not values) in deeply nested structure (workaround) for more test cases.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11119732]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found