develooper Front page | perl.perl5.porters | Postings from August 2012

Re: fixing smartmatch just hard enough (and when, too)

Thread Previous | Thread Next
David Golden
August 17, 2012 05:51
Re: fixing smartmatch just hard enough (and when, too)
Message ID:
On Fri, Aug 17, 2012 at 8:20 AM, Ed Avis <> wrote:
> Good point.  I was assuming that there is a concept of scalar equality defined
> by the language and accessible to the programmer directly.  But this is not the

Perl gives you numeric and string equality (and allows overriding of
each).  Consider this:

    use v5.10;
    use strict;
    use warnings;
    use bignum;
    use Scalar::Util qw/refaddr/;

    my $x = 42;
    my $y = 42;

    say '$x is object at ' . refaddr($x);
    say '$y is object at ' . refaddr($y);

    # output:
    # $x is object at 40813776
    # $y is object at 40814952

If you tested C<< $x in ( $y ) >>, is that true or false?  $x and $y
are different objects, yet the compare true numerically.  Is $x in the
list or not?

Thus your conception of "in" is visually elegant -- and I like that --
but just isn't specific enough for the dynamic nature of Perl, whereas
junctions force the programmer to clarify what comparison they
actually want for a membership test.

    C<< $x == any( $y ) >>
    C<< refaddr($x) == any( map { refaddr $_ } $y ) >>

-- David

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About