in reply to [5.10] =~ vs ~~

Since @a contains the same thing in both cases I think it's a bug. perlsyn says
Any Regex pattern match $a =~ /$b/

So they should be equivalent.

(The bug is still in blead)

Update: it's now on p5p.

Replies are listed 'Best First'.
Re^2: [5.10] =~ vs ~~
by Arunbear (Prior) on Sep 01, 2008 at 10:06 UTC
    perlsyn also says
    The "matching code" doesn't represent the real matching code, of course: it's just there to explain the intended meaning.
    Also ~~ is a boolean operator and perlsyn doesn't specify what it should do in list context (though admittedly it doesn't seem that smart if it can't do-what-you-mean).
      Also ~~ is a boolean operator and perlsyn doesn't specify what it should do in list context

      but when you add a use Data::Dumper; print Dumper \@a you can see that it does the same thing as =~ in list context.

      What's really weird is that say scalar (my @a = ...) behaves differently from my @a = ...; say scalar @a;.

      I think the doesn't represent the real matching code remark mostly means that the real matching code is optimized in many cases, but that it should semantically still do the same thing.

        hmm, re behaviour in list context, I'm getting different results from you:
        use strict; use warnings; use Data::Dumper; use feature qw/say/; my @a1 = 'aaa' ~~ /./g; my @a2 = 'aaa' =~ /./g; say Data::Dumper->Dump([\@a1, \@a2], [qw/smart_match re_match/]);
        gives me
        $smart_match = [ 1 ]; $re_match = [ 'a', 'a', 'a' ];
        with v5.10.0 built for i686-linux
        What's really weird is that say scalar (my @a = ...) behaves differently from my @a = ...; say scalar @a;

        I personally believe that actually:

        $ perl -wMstrict -E 'say "@{[q|aaa| =~ /./g]}"' a a a $ perl -wMstrict -E 'say "@{[q|aaa| ~~ /./g]}"' 1

        FWIW, I realized this while writing the code for Finding differences in binary files: the line that starts with my @l was originally unnecessarily broken in two statements, the first of which was a match with ~~: then I thought I could condense them into one, but for some reason "it didn't work" - until I changed the operator to =~ "just to be sure," that is...

        --
        If you can't understand the incipit, then please check the IPB Campaign.
      Also ~~ is a boolean operator and perlsyn doesn't specify what it should do in list context

      I personally believe that in Perl 6 it is going to substitute =~ altogether, though, and while this is certainly not the case in Perl 5, one would still perlishly and dwimmily expect its return value to be richer than that...

      --
      If you can't understand the incipit, then please check the IPB Campaign.