gpt4 book ai didi

pragma - 什么是 perl 实验特性,postderef?

转载 作者:行者123 更新时间:2023-12-03 22:23:48 24 4
gpt4 key购买 nike

我看到use experimental 'postderef'用于 Moxie这里on line 8 .我只是对它的作用感到困惑。 experimental 的手册页也很模糊,

allow the use of postfix dereferencing expressions, including in interpolating strings



任何人都可以展示在没有 pragma 的情况下您必须做什么,以及 pragma 使什么变得更容易或可能?

最佳答案

它是什么

这很简单。这是一个有起有落的语法糖。不再需要编译指示,因为该功能是 5.24 的核心。但是为了在 5.20 和 5.24 之间支持该功能,必须启用它:use experimental 'postderef' .在提供的示例中,在 Moxie 中,它用于 one line其中有 $meta->mro->@* ;没有它你必须写 @{$meta->mro} .

概要

这些直接来自 D Foy 的博客,以及我写的用于比较的惯用 Perl。

D Foy example                    Idiomatic Perl
$gimme_a_ref->()->@[0]->%* %{ $gimme_a_ref->()[0] }
$array_ref->@* @{ $array_ref }
get_hashref()->@{ qw(cat dog) } @{ get_hashref() }{ qw(cat dog) }

这些例子完全由 D Foy 提供,
D Foy example                    Idiomatic Perl
$array_ref->[0][0]->@* @{ $array_ref->[0][0] }
$sub->&* &some_sub

论据
  • postderef允许链接。
  • postderef_qq使复杂的插入标量字符串变得更容易。

  • 反对意见

    D Foy 根本没有提供
  • 失去印记的意义。而在此之前,您通过查看最左侧的印记就知道“类型”是什么。现在,你不知道,直到你阅读了整个链条。这似乎削弱了对印记的任何论点,迫使您在知道预期内容之前阅读整个链条。也许争论印记是一个好的设计决定的日子已经结束了?但是,又一次,perl6 is still all about them .这里缺乏一致性。
  • 过载 ->意思是,作为类型。所以现在你有 $type->[0][1]->@*表示取消引用为 $type,并强制输入。
  • 切片在基元上没有类似的语法。
    my @foo = qw/foo bar baz quz quuz quuuz/;
    my $bar = \@foo;

    # Idiomatic perl array-slices with inclusive-range slicing
    say @$bar[2..4]; # From reference; returns bazquzquuz
    say @foo[2..4]; # From primitive; returns bazquzquuz

    # Whizbang thing which has exclusive-range slicing
    say $bar->@[2,4]; # From reference; returns bazquz
    # Nothing.

  • 来源
  • Brian D Foy in 2014. .
  • Brian D Foy in 2016. .
  • 关于pragma - 什么是 perl 实验特性,postderef?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45083385/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com