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
# 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) {
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
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$role_reqs
.
format INHERIT_POD =
=head1 NAME
@*
$mycl
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$handles
.
format ATTR_NARROW
$handles
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$handles
.
format ATTRHEAD_POD =
=head1 ATTRIBUTES
.
format ATTR_POD =
$self->mins} ~~ @{$setObj->mins} and @{$self->maxs} ~~ @{$setObj->maxs});
}
# 判断两个集合是否不相等
sub notEqual {
my ($self, $setObj) = @_;
return !(@{$self->mins} ~~ @{$setObj->
mins} and @{$self->maxs} ~~ @{$setObj->maxs});
}
# 判断当前集合是否包含另一个集合(包含相等情况)
sub isContain {
my ($self, $setObj) = @_;
if ($self->isEqual($setObj))
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$role_reqs
.
format INHERIT_POD =
=head1 NAME
@*
$myclass
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$handles
.
format ATTR_NARROW
$handles
^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ~~
$handles
.
format ATTRHEAD_POD =
=head1 ATTRIBUTES
.
format ATTR_POD =
=he
up; $i++) {
my @mm = split /,/, $group->[$i][3];
next unless $user ~~ @mm || $group->[$i][0] eq $user;
if (!$detail) {
push @rows, $
return undef unless $res->[0] == 200;
my @mm = split /,/, $res->[2]{members};
return $user ~~ @mm ? 1:0;
}
$SPEC{get_max_uid} = {
v => 1.1,
summary => 'Get maximum UID used',
args
for ($min_gid .. $max_gid) {
do { $gid = $_; last } unless $_ ~~ @gids;
}
return [412, "Can't find available GID"]
-----------------------------------
# 1) Ignore fenced code blocks (```lang … ``` or ~~~ … ~~~)
# We match them first, then (*SKIP)(*F) so the engine
# jumps past the
--------------------------------------------------
# 1) Fenced-code guard (```...``` or ~~~...~~~)
#---------------------------------------------------------
$MD_SKIP_FENCED
cks with backticks, except the extended version uses tilde characters.
For example:
~~~
<div>
~~~
You can see example of this regular expression along with test units here: L<https://re
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
opy(d);
}
else
d = &PL_sv_undef;
assert(e);
if (SvGMAGICAL(e))
e = sv_mortalcopy(e);
/* ~~ undef */
if (!SvOK(e)) {
return !SvOK(d);
}
else if (SvROK(e)) {
/* First of all, handle ov
rt_amg, AMGf_noleft);
#else
HV* stash = SvSTASH(SvRV(e));
GV* gv = gv_fetchmeth_pvn(stash, "(~~", 3, -1, 0);
if (gv) {
UNOP myop = {
.op_flags = OPf_STACKED | OPf_WANT_SCALAR,
K;
POPSTACK;
CATCH_SET(oldcatch);
}
#endif
if (sv)
return SvTRUEx(sv);
}
/* ~~ qr// */
if (SvTYPE(SvRV(e)) == SVt_REGEXP) {
dSP;
REGEXP* re = (REGEXP*)SvRV(e);
PMOP*
007'; # VERSION
my $text = <<'MARKDOWN';
**About smart match**
Smart matching, via the operator `~~`, was introduced in perl 5.10 (released
2007). It's inspired by Perl 6 (now called Raku)'s `given/
) more. Interesting things begin when the left/right hand
side is an array/hash/code/object. `$str ~~ @ary_of_strs`, probably the most
common use-case for smart matching, can do value-in-array checkin
lent
to `grep { $str eq $_ } @ary_of_strs` but with short-circuiting capability. Then
there's `$re ~~ @ary_of_strs` which can perform regex matching over the elements
of array. Now what about when the
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
=> "-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
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$typedesc
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$typedesc
~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
=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
#$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
| $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;
ft( @_ );
my $str = $self->children->map(sub{ $_->as_markdown })->join( '' );
return( "~~${str}~~" );
}
sub as_pod
{
my $self = shift( @_ );
my $str = $self->children->map(sub{ $_->as
Markdown::Parser> and inherits from L<Markdown::Parser::Element>
For example:
~~This whole sentence is wrong~~
=head1 METHODS
=head2 as_markdown
Returns a string representation of the strike-
te @pure_statements;
@pure_statements = ();
state $VALIDATE_PURE_GIVEN = qr{
\A given (?<GIVEN> (?<ws_post_kw> $OWS ) \(
(?<ws_pre_expr> $OWS )
return !defined $left;
}
# 2. Objects on the RHS can't be handled (at all, because no ~~ overloading available)...
croak 'Smart matching an object breaks encapsulation'
if $ri
removed in this version of Perl
use Switch::Back; # But this module brings them back
given ($some_value) {
when (1) { say 1; }
when ('a') { say 'a'; continue; }
y ($self, $type) = @_;
given ($type) {
when (STORED) { $self->{type} ~~ ATTR_STORED }
when (CACHED) { $self->{type} ~~ ATTR_CACHED }
when (KEY) { $self->{type} ~~ ATTR_KEY }
when (ANY