Group
Extension

Matches 27

perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perlop.pod ( view source; MetaCPAN )
nonassoc	named unary operators
    nonassoc	< > <= >= lt gt le ge
    nonassoc	== != <=> eq ne cmp ~~
    left	&
    left	| ^
    left	&&
    left	|| //
    nonassoc	..  ...
    right	?:
    right	= +
r greater than the right
argument.
X<cmp>

Binary "~~" does a smartmatch between its arguments.  Smart matching
is described in the next section.
X<~~>

"lt", "le", "ge", "gt" and "cmp" use the collat
tmatch Operator

First available in Perl 5.10.1 (the 5.10.0 version behaved differently),
binary C<~~> does a "smartmatch" between its arguments.  This is mostly
used implicitly in the C<when> constru
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perlsyn.pod ( view source; MetaCPAN )
hin a C<foreach>
loop or a C<given> block, it executes the statement only if the smartmatch
C<< $_ ~~ I<EXPR> >> is true.  If the statement executes, it is followed by
a C<next> from inside a C<foreac
XPR) BLOCK elsif (EXPR) BLOCK ...
    unless (EXPR) BLOCK elsif (EXPR) BLOCK ... else BLOCK

    given (EXPR) BLOCK

    LABEL while (EXPR) BLOCK
    LABEL while (EXPR) BLOCK continue BLOCK

    LABEL
 to use the highly experimental C<given>, that could be
written like this:

    use v5.10.1;
    given ($var) {
	when (/^abc/) { $abc = 1 }
	when (/^def/) { $def = 1 }
	when (/^xyz/) { $xyz = 1 }
	def
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DOM, 2025; MetaCPAN )
perl/pod/perl5110delta.pod ( view source; MetaCPAN )
es.

=head2 Smart match changes

=head3 Changes to type-based dispatch

The smart match operator C<~~> is no longer commutative. The behaviour of
a smart match now depends primarily on the type of its
t like the other code references (even if they
choose to ignore it).

=item *

C<%hash ~~ sub {}> and C<@array ~~ sub {}> now test that the subroutine
returns a true value for each key of the hash (or
 are no longer
treated specially when appearing on the left of the C<~~> operator,
but like any vulgar scalar.

=item *

C<undef ~~ %hash> is always false (since C<undef> can't be a key in a
hash). No
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perl5120delta.pod ( view source; MetaCPAN )
in in
subsequent 5.10 releases.

=head3 Changes to type-based dispatch

The smart match operator C<~~> is no longer commutative. The behaviour of
a smart match now depends primarily on the type of its
t like the other code references (even if they
choose to ignore it).

=item *

C<%hash ~~ sub {}> and C<@array ~~ sub {}> now test that the subroutine
returns a true value for each key of the hash (or
 are no longer
treated specially when appearing on the left of the C<~~> operator,
but like any vulgar scalar.

=item *

C<undef ~~ %hash> is always false (since C<undef> can't be a key in a
hash). No
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/Porting/checkpodencoding.pl ( view source; MetaCPAN )
 # Test cases
        $file ~~ m[Pod-Simple/t];

    my ($in_pod, $has_encoding, @non_ascii);

    FILE: while (my $line = <$fh>) {
        chomp $line;
        if ($line ~~ /^=[a-z]+/) {
            
     if ($in_pod) {
            if ($line ~~ /^=encoding (\S+)/) {
                $has_encoding = 1;
                last FILE;
            } elsif ($line ~~ /[^[:ascii:]]/) {
                my $enc
 "$encoding->{Name}?" : 'unknown!'),
                };
            }
        }

        if ($line ~~ /^=cut/) {
            $in_pod = 0;
        }
    }

    if (@non_ascii and not $has_encoding) {
 
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perl5101delta.pod ( view source; MetaCPAN )
ed.

=head2 Smart match changes

=head3 Changes to type-based dispatch

The smart match operator C<~~> is no longer commutative. The behaviour of
a smart match now depends primarily on the type of its
t like the other code references (even if they
choose to ignore it).

=item *

C<%hash ~~ sub {}> and C<@array ~~ sub {}> now test that the subroutine
returns a true value for each key of the hash (or
 are no longer
treated specially when appearing on the left of the C<~~> operator,
but like any vulgar scalar.

=item *

C<undef ~~ %hash> is always false (since C<undef> can't be a key in a
hash). No
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DOM, 2025; MetaCPAN )
perl/pod/perlfaq4.pod ( view source; MetaCPAN )
 item is
contained in an array or a hash:

	use 5.010;

	if( $item ~~ @array )
		{
		say "The array contains $item"
		}

	if( $item ~~ %hash )
		{
		say "The hash contains $item"
		}

With earlier ver
 answer
with the least amount of work:

	use 5.010;

	if( @array1 ~~ @array2 )
		{
		say "The arrays are the same";
		}

	if( %hash1 ~~ %hash2 ) # doesn't check values!
		{
		say "The hash keys are th
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perlform.pod ( view source; MetaCPAN )
ormat, picture line>
X<@> X<^> X<< < >> X<< | >> X<< > >> X<#> X<0> X<.> X<...>
X<@*> X<^*> X<~> X<~~>

   @    start of regular field
   ^    start of special field
   <    pad character for left jus
ble width field for next line of a multi-line value
   ~    suppress line with all fields empty
   ~~   repeat line until all fields are exhausted

Each field in a picture line starts with either "@" 
    $text = "line 1\nline 2\nline 3";
      format STDOUT =
      Text: ^*
            $text
      ~~    ^*
            $text
      .
   Output:
      Text: line 1
            line 2
            line 
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/install_lib.pl ( view source; MetaCPAN )
| $Is_NetWare);

    if ($p1 ne $p2) {
	my($dev1, $ino1, $dev2, $ino2);
	($dev1, $ino1) = stat($p1);
	($dev2, $ino2) = stat($p2);
	($dev1 ~~ $dev2 && $ino1 ~~ $ino2);
    }
    else {
	1;
    }
}

1;
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DOM, 2025; MetaCPAN )
perl/dist/Storable/t/freeze.t ( view source; MetaCPAN )
#$a = 2; $a->[1] = undef;
        $b = thaw freeze $a;
        @a = map { ~~ exists $a->[$_] } 0 .. $#$a;
        @b = map { ~~ exists $b->[$_] } 0 .. $#$b;
        ok 20, "@a" eq "@b";
    ';
}
else 
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/lib/overload.pm ( view source; MetaCPAN )
            => "-X",
    dereferencing       => '${} @{} %{} &{} *{}',
    matching            => '~~',
    special             => 'nomethod fallback =',
);

my %ops_seen;
for $category (keys %ops) {
s	  => '<>',
 filetest         => '-X',
 dereferencing	  => '${} @{} %{} &{} *{}',
 matching	  => '~~',
 special	  => 'nomethod fallback ='

Most of the overloadable operators map one-to-one to these 
oad was introduced in Perl 5.12.

=item * I<Matching>

The key C<"~~"> allows you to override the smart matching logic used by
the C<~~> operator and the switch construct (C<given>/C<when>).  See
L<pe
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DOM, 2025; MetaCPAN )
perl/lib/Pod/Functions.pm ( view source; MetaCPAN )
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $typedesc 
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    $typedesc 
 ~~  ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perl5140delta.pod ( view source; MetaCPAN )
pty list if the block was exited by C<break>.  Thus you
can now write:

    my $type = do {
     given ($num) {
      break     when undef;
      "integer" when /^[+-]?[0-9]+$/;
      "float"   when /
e operators is used in
an unparenthesised argument:

  < > <= >= lt gt le ge
  == != <=> eq ne cmp ~~
  &
  | ^
  &&
  || //
  .. ...
  ?:
  = += -= *= etc.
  , =>

=head3 Smart-matching against array
 resulted in a successful match:

    my @a = qw(a y0 z);
    my @b = qw(a x0 z);
    @a[0 .. $#b] ~~ @b;

This odd behaviour has now been fixed [perl #77468].

=head3 Negation treats strings differen
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perl5160delta.pod ( view source; MetaCPAN )

=over

=item *

C<~~> now correctly handles the precedence of Any~~Object, and is not tricked
by an overloaded object on the left-hand side.

=item *

In Perl 5.14.0, C<$tainted ~~ @array> stopped wo
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perlcheat.pod ( view source; MetaCPAN )
se { }
  **                     unless  (e) { } elsif (e) { } else { }
  ! ~ \ u+ u-            given   (e) { when (e) {} default {} }
  =~ !~
  * / % x                 NUMBERS vs STRINGS  FALSE vs TR
           == !=      eq ne
  < > <= >= lt gt le ge   < > <= >=  lt gt le ge
  == != <=> eq ne cmp ~~  <=>        cmp
  &
  | ^             REGEX MODIFIERS       REGEX METACHARS
  &&              /i c
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/lib/overload.t ( view source; MetaCPAN )
                                 [ 1, 2, 0 ], 0 ];

	$e = '"abc" ~~ (%s)';
	$subs{'~~'} = $e;
	push @tests, [ "abc", $e, '(~~)', '(NM:~~)', [ 1, 1, 0 ], 0 ];

	$subs{'-X'} = 'do { my $f = (%s);'
		   
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perldiag.pod ( view source; MetaCPAN )
ve caught it
earlier.

=item Repeated format line will never terminate (~~ and @# incompatible)

(F) Your format contains the ~~ repeat-until-blank sequence and a
numeric field that will never go blan
.

=item Smart matching a non-overloaded object breaks encapsulation

(F) You should not use the C<~~> operator on an object that does not
overload it: Perl refuses to use the object's underlying stru
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/pod/perl5143delta.pod ( view source; MetaCPAN )
nc may be used together.

=item *

The smartmatch operator (C<~~>) was changed so that the right-hand side
takes precedence during C<Any ~~ Object> operations.

=item *

A bug has been fixed in the ta
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DROLSKY, 2025; MetaCPAN )
perl/overload.h ( view source; MetaCPAN )
  concat_amg,		/* 0x3f .        */
    concat_ass_amg,	/* 0x40 .=       */
    smart_amg,		/* 0x41 ~~       */
    ftest_amg,		/* 0x42 -X       */
    regexp_amg,		/* 0x43 qr       */
    max_amg_code
perl ( C/CO/CONTRA/perl-5.43.5.tar.gz, DOM, 2025; MetaCPAN )
perl/dist/B-Deparse/t/deparse.t ( view source; MetaCPAN )
emented on this Perl version"
# 52 implicit smartmatch in given/when
given ('foo') {
    when ('bar') { continue; }
    when ($_ ~~ 'quux') { continue; }
    default { 0; }
}
####
# 53 conditions in e

Powered by Groonga
Maintained by Kenichi Ishigaki <ishigaki@cpan.org>. If you find anything, submit it on GitHub.