develooper Front page | perl.perl5.porters | Postings from January 2008

Negated Smart Match

Thread Next
From:
Ron Blaschke
Date:
January 3, 2008 01:38
Subject:
Negated Smart Match
Message ID:
477CACFD.4000505@rblasch.org
Congrats to you all to the recent Perl 5.10 release!  I'm just taking
some time to explore the new features and I have a quick question.
The new smart matching operator C<~~> is great, is there a negated
version of it?  I tried C<!~~> but that doesn't quite work as expected:

$ cat t.pl
use strict;
use warnings;

use feature qw( :5.10 );

my $value = 1;
my @array = (1, 2, 3);

if ($value ~~ @array) {
    say "found";
}

if ($value !~~ @array) {
    say "not found";
}


$ perl t.pl
found
not found


$ perl -MO=Deparse t.pl
use warnings;
use strict 'refs';
BEGIN {
    $^H{'feature_say'} = q(1);
    $^H{'feature_state'} = q(1);
    $^H{'feature_switch'} = q(1);
}
my $value = 1;
my(@array) = (1, 2, 3);
if ($value ~~ \@array) {
    say 'found';
}
if (not $value =~ ~@array) {
    say 'not found';
}
t.pl syntax OK


Seems like
C<$value !~~ @array> is actually parsed as
C<$value !~ ~@array>.

Regards,
Ron

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About