EXPR1)) {
if ($_ =~ (EXPR2)) { ... }
}
[Update: the C<=~> operator has been renamed C<~~>.]
=head3 Table 1: Matching a switch value against a case value
$a $b Type of Ma
an operator on every case, simply provide an empty given,
to be read as "given nothing...":
given () {
when $a.isa(Ant) { ... }
when $b.isa(Bat) { ... }
when $c.isa(Cat) {
}
}
This works because =~ is considered a boolean operator.
[Update: The operator is C<~~> now.]
RFC:
catch not &TooSevere => { ... }
Now:
when not &TooSevere { ... }
The unar
be expressed as methods or smart
patterns.
if $filename.:e { say "exists" }
# or
if $filename ~~ :e { say "exists" }
=head2 Junction Operators
Perl 6 introduces a new scalar data-type: the B<ju
DOC use Pod6::Markovian;
or:
DOC BEGIN {
use Pod6::Literate;
if ($?DOC ~~ /short/) {
literate_sequence(<
NAME
AUTHOR
(\w+)
}
rule value {
(\w+)
}
rule entry {
<key> '=' <value> (';')?
}
}
my $text = "foo=bar;me=self;";
if $text ~~ /^<Properties::entry>+$/ {
"Matched".say;
} else {
"Not Matched".say;
}
mplex> with
a C<NaN> in real or imaginary part may be considered a C<NaN> itself (and
C<(NaN + 1i) ~~ NaN> is C<True>).
Coercion of a C<Complex> to any C<Real> returns the real part (coerced, if
nece
to provide a generic "smart
match" operator.
So he did. It's called C<=~>.
[Update: Now called C<~~> instead.]
Yes, the humble Perl 5 "match a string against a regex" operator is
promoted in Perl 6
nce
INCLUSIVE OR || or
EXCLUSIVE OR ~~ xor
DEFINED OR // err
[Update: High
$x = $cond ? $true : $false;
$s = "con" ~ "cat" ~ "enate"; $s = "con" . "cat" . "enate";
$str ~~ /$pattern/; $str =~ /$pattern/;
Any time you see a C<~> in Perl 6, it has something t
of not knowing the language at all or from knowing Perl 5, it's enough to
know initially that C<~~> will pattern match on strings).
=head2 New Perl 6 Syntax
Perl 6 also has some brand-new syntax.
inst
the current topic. That is,
doit() when 42;
is exactly equivalent to
doit() if $_ ~~ 42;
This is particularly useful for list comprehensions:
@lucky = ($_ when /7/ for 1..100);
my @keys = keys %{LOG4PERL_LEVELS()};
my ($minkey, $maxkey) = (min(@keys), max(@keys));
given ( $level ) {
when ( $_ < $minkey ) { $l4p_level = 2 * LOG4PERL_LEVELS->{$minkey} }
when
->toXML ($name);
$root->appendChild ($xmlElem) if $xmlElem;
}
}
# return the same value as given (but others may override it - eg,
# Boolean changes here 1 to 'true'
sub _express_value {
sh
s/ \~ /\n/g; # replace _~_ with \n
s/ \~\~ / \~ /g; # stuffed ~~ cleanout
s/^\#.*?\n/\n/mg; # # at the start of every line -> gone
s/\s\#.*?\n
);
return %s;
}
}
sub _expand_axes {
my $a = shift;
use feature 'switch';
given ( $a ) {
when ('taxo') { # "taxo" s
rtion_id>, ...)
This method takes a list of assertion IDs and returns the assertion(s) with the given (subject)
ID(s). If the assertion is not identifiable, C<undef> will be returned in its place. Ca
return ()
## }
my $procedural = (
$pkg eq 'main'
|| defined $args{'mode'} && $args{'mode'} ~~ qr/:procedural/
) ? 1 : 0
;
feature->import(':5.10');
indirect->unimport(':fatal');
autodie-
_flag.
{
my @go_attrs = MooseX::Getopt::GLD->meta->get_attribute_list;
my $help_attr = 'help_flag' ~~ @go_attrs ? 'help_flag' : 'help';
has $help_attr => (
traits => [ qw/ Getopt / ],
c
)
=item answered_list($username, $max_id, $since_id)
Gets a list of questions and answers from given (or default) username. Returns an arrayref of WWW::Formspring::Response objects.
If max_id parame
th => 'Games::RailRoad::Node', sub_name => 'nodes';
$_->require for __PACKAGE__->nodes;
given ( $save->{version} ) {
when ( $_ > __PACKAGE__->VERSION ) {
die "uh, loading
n in vertical /
# horizontal rails.
my $frac = $train->frac;
$frac += $dir ~~ [ qw{ e n s w } ] ? 1/5 : sqrt(2)/10;
if ( $frac >= 1 ) {
# eh, changing node
in the middle of two nodes, it's not precise enough.
$x %= $TILELEN;
$y %= $TILELEN;
given ($x) {
when( $_ > $TILELEN * (1-$prec) ) { $col++; }
when( $_ <= $TILELEN * $pre
if($recurse) {
foreach my $val (@mapped) {
given(reftype $val) {
when('HASH') {
for(ke
----------
sub graph {
my ($self, $out_fn) = @_;
my @rras = map $_->rras, $self->rrdbs;
given ( $self->range || '' ) { # make sure it's defined so when ( /.../ ) doesn't whinge
when ( ''
nalogous
to C<switch> and C<case> in other languages, so the code
above could be written as
given($_) {
when (/^abc/) { $abc = 1; }
when (/^def/) { $def = 1; }
when (/^xyz/) { $xyz = 1; }
def
}
This construct is very flexible and powerful. For example:
use feature ":5.10";
given($foo) {
when (undef) {
print '$foo is undefined';
}
when ("foo") {
print '$foo is
check($foo) is true';
}
default {
die q(I don't know what to do with $foo);
}
}
C<given(EXPR)> will assign the value of EXPR to C<$_>
within the lexical scope of the block, so it's simi