加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl6 – 不能在`qqww`或`qqww:to`结构中使用冒号对

发布时间:2020-12-15 23:24:42 所属栏目:大数据 来源:网络整理
导读:我想使用Class生成一个json行,我会覆盖gist方法,以便它打印出我想要的内容: my $ak = '7111ac873c9dcd5fc335ded47630d050';my $st = '1523451601875';my $ifo = 'true';my $uu = "15778787898988090";class Stay { has $.ak is rw = '7111ac873c9dcd5fc335d
我想使用Class生成一个json行,我会覆盖gist方法,以便它打印出我想要的内容:

my $ak = '7111ac873c9dcd5fc335ded47630d050';
my $st = '1523451601875';
my $ifo = 'true';
my $uu = "15778787898988090";

class Stay {
  has $.ak  is rw = '7111ac873c9dcd5fc335ded47630d050';
  has $.uu  is rw;
  has $.ifo is rw;
  has $.st  is rw;

  method gist() {
    #return qqww/{"ev":"app","ak":"$!ak","uu":"$!uu","ifo":"$!ifo","st":"$!st"}/;

    return qqww:to「EOF」;
    {"ev":"app","st":"$!st"}
    EOF
  }
}

say Stay.new(uu => $uu,ifo => $ifo,st => $st);

但失败了:

===SORRY!=== Error while compiling /Users/ohmycloud/Desktop/stay.pl6
Confused
at /Users/ohmycloud/Desktop/stay.pl6:18
------>     {"ev":?"app","ifo":"$!i
    expecting any of:
        colon pair

我想要的是:

{"ev":"app","ak":"7111ac873c9dcd5fc335ded47630d050","uu":"15778787898988090","ifo":"true","st":"1523451601875"}

为什么我不能在qqww或qq中使用冒号对:结构?

解决方法

你可以使用 unquoting:

method gist() {
    return '{"ev":"app","ak":"qq[$!ak]","uu":"qq[$!uu]","ifo":"qq[$!ifo]","st":"qq[$!st]"}':
}

将返回

{"ev":"app","st":"1523451601875"}

如果你使用qqww或类似的话,冒号会妨碍你.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读