我想创建一个用户定义的"元音"字符类,它将匹配任何文字英语元音字母(a,e,i,o,u)以及任何这些字母与任何可能的变音符号:ắắ úåų̄ẹ等
这是我试过的,但它不起作用:
> my $vowel = / <[aeiou]> <:Sk>* /
/ <[aeiou]> <:Sk>* /
> "áei" ~~ m:g/ <$vowel> /
(?e? ?i?)
Run Code Online (Sandbox Code Playgroud) 两个相关的问题.Perl 6非常聪明,它将字形理解为一个字符,无论是一个Unicode符号(如ä
,U+00E4
)还是两个或多个组合符号(如p?
和??
).这个小代码
my @symb;
@symb.push("ä");
@symb.push("p" ~ 0x304.chr); # "p?"
@symb.push("?" ~ 0x323.chr); # "??"
say "$_ has {$_.chars} character" for @symb;
Run Code Online (Sandbox Code Playgroud)
给出以下输出:
ä has 1 character
p? has 1 character
?? has 1 character
Run Code Online (Sandbox Code Playgroud)
但有时我希望能够做到以下几点.1)从中删除变音符号ä
.所以我需要一些方法
"ä".mymethod ? "a"
Run Code Online (Sandbox Code Playgroud)
2)将"组合"符号拆分成部分,即拆分p?
成p
和Combining Macron U+0304
.例如以下内容bash
:
$ echo p? | grep . -o | wc -l
2
Run Code Online (Sandbox Code Playgroud) 我想过滤以以下元素@array
开头的元素@search
:
my @array = "aaaaa" .. "fffff";
my @search = "aaaa" .. "cccc";
.put for @array .grep: /^ @search /;
Run Code Online (Sandbox Code Playgroud)
问题是需要19秒.所以,我"预编译"的regex
对grep
,整个程序是这样的:
my @array = "aaaaa" .. "fffff";
my @search = "aaaa" .. "cccc";
my $search = "/@search.join('|')/".EVAL;
.put for @array .grep: * ~~ /^ <$search> /;
Run Code Online (Sandbox Code Playgroud)
现在需要0.444秒.
问题:是否有内置的Perl 6方法来做这些事情?像插入junction
一个regex
......
如果我理解正确,当我为一个array
字符串赋值时< ... >
,我应该转义特殊符号\
:
> my @array = < \\ a b>
[\ a b]
> my @array = < \< a b>
[< a b]
> my @array = < \<de\< a b>
[<de< a b]
Run Code Online (Sandbox Code Playgroud)
使用反斜杠并不总是方便,有时代码可能会变得模糊不清.
有没有更好的方法将包含特殊字符的字符串列表传递给数组?
是否有惯用的方法或内置方法来连接两个Sets
字符串?
这就是我想要的:
> my Set $left = <start_ begin_>.Set
set(begin_ start_)
> my Set $right = <end finish>.Set
set(end finish)
> my Set $left_right = ($left.keys X~ $right.keys).Set
set(begin_end begin_finish start_end start_finish)
Run Code Online (Sandbox Code Playgroud)
或者,如果有两个以上:
> my Set $middle = <center_ base_>.Set
> my Set $all = ([X~] $left.keys, $middle.keys, $right.keys).Set
set(begin_base_end begin_base_finish begin_center_end begin_center_finish start_base_end start_base_finish start_center_end start_center_finish)
Run Code Online (Sandbox Code Playgroud) 我只是开始上课,所以我不了解基础知识.
我想要一个方法来构造regex
使用对象的属性:
class TEST {
has Str $.str;
method reg {
return
rx/
<<
<[abc]> *
$!str
<!before foo>
/;
}
}
my $var = TEST.new(str => 'baz');
say $var.reg;
Run Code Online (Sandbox Code Playgroud)
尝试运行此程序时,我收到以下错误消息:
===SORRY!=== Error while compiling /home/evb/Desktop/p6/e.p6
Attribute $!str not available inside of a regex, since regexes are methods on Cursor.
Consider storing the attribute in a lexical, and using that in the regex.
at /home/evb/Desktop/p6/e.p6:11
------> <!before foo>?<EOL>
expecting any of:
infix stopper
Run Code Online (Sandbox Code Playgroud)
那么,这样做的正确方法是什么?
为什么不:=
导出带有绑定的变量的值?
$ cat myModule.pm6
our $a is export = 42;
our $b is export := $a;
$ cat program.p6
use myModule;
say $a;
say $b;
$ perl6 program.p6
42
(Any) # Why?
Run Code Online (Sandbox Code Playgroud) 每次我运行perl6
进入REPL
模式时,它都会创建一个.precomp
目录,这也会减慢提示的外观.如果.precomp
目录已存在,则提示几乎立即出现,否则perl6
需要几秒钟才能创建.
有没有办法禁用此功能?
我希望整个body
有一个虚线网格
body {
background-image: radial-gradient(black 1px, transparent 0);
background-size: 40px 40px;
}
Run Code Online (Sandbox Code Playgroud)
问题是我想移动它,以便在点 (0, 0) 处放置一个点,即body
. 所以整个结构应该在-20px, -20px
。或者可能有更好的解决方案?
我要构建一个定制的虚拟键盘,所以这是我遇到的第一个问题。我有一个input
元素,其值是从外部更改的,在我的例子中,通过按下按钮来更改。问题是好像没有办法触发正常'change'
事件。
在 之外单击input
或按 Enter 键都不会产生任何结果。
解决这个问题的正确方法可能是什么?
<template>
<div class="app-input">
<input @change="onChange" type="text" v-model="value" ref="input">
<button @click="onClick">A</button>
</div>
</template>
<script>
export default {
name: "AppInput",
data() {
return {
inputDiv: null,
value: ""
};
},
props: {
msg: String
},
methods: {
onClick() {
this.value = this.value + "A";
this.inputDiv.focus();
},
onChange() {
alert("changed");
}
},
mounted() {
this.$nextTick(() => {
this.inputDiv = this.$refs.input;
});
}
};
</script>
Run Code Online (Sandbox Code Playgroud)
整支笔都可以在这里找到。