Wikia

Perl6 Wiki

Smart match operator

Talk0
77pages on
this wiki

In Perl6 the Smart Match Operator is ~~ and its inversed form is !~~.

Contents

Description Edit

The binary operator ~~ matchs a regular expression object to a string. The !~~ operator is !($str ~~ $regex).

Examples Edit

Simple Demonstration Edit

if 'part1' ~~ /<digit>/ {
    say "Hello World";
}

Searching inside an arrayEdit

my @list = 1,2,3; 
say (1 ~~ any(@list)) ?? "yes" !! "nope" ;
say (6 ~~ any(@list)) ?? "yes" !! "nope" ;

Searching defined hash keysEdit

my %pets = (cats=>1 ,dogs=>2, dodos=>0); 
say ('pigs' ~~ any(keys %pets)) ?? "yes" !! "nope" ;
say ('cats' ~~ any(keys %pets)) ?? "yes" !! "nope" ;

See also Edit

Advertisement | Your ad here

Photos

Add a Photo
10photos on this wiki
See all photos >

Recent Wiki Activity

See more >

Around Wikia's network

Random Wiki