in reply to Python 'is' command

G'day betmatt,

"... do exactly the same in Perl using a ref command in conjunction with '=='."

Depending on context, it may be worthwhile using ref to ensure you're actually comparing references; however, it's not needed for the comparison.

Instead of ==, I'd probably choose eq and do the comparison test like this:

$ref1 eq $ref2

Here's a short example:

$ perl -E ' my @x = ({}, []); my $y = $x[0]; say for @x, $y; say $_->[0] eq $_->[1] ? "Y" : "N" for [@x], [$x[0], $y]; ' HASH(0x600003a70) ARRAY(0x600076050) HASH(0x600003a70) N Y

— Ken

Replies are listed 'Best First'.
Re^2: Python 'is' command
by haukex (Archbishop) on Aug 15, 2019 at 09:53 UTC
    Instead of ==, I'd probably choose eq

    eq can be overloaded just like ==, as I showed here, and is therefore more like Python's == instead of its is.

      I'm familiar with overloading. I was just showing another way to do it which, as far as I could see, no one else had mentioned.

      — Ken