gpt4 book ai didi

perl - Perl 中 `$this` 、 `@that` 和 `%those` 之间有什么区别?

转载 作者:行者123 更新时间:2023-12-03 07:01:17 27 4
gpt4 key购买 nike

Perl 中的 $this@that%those 有什么区别?

最佳答案

Perl 符号的有用助记符是:

  • $calar
  • @rray
  • %灰

Matt Troutblog.fogus.me 上写了一篇很棒的评论关于 Perl sigils 我认为很有用,所以粘贴在下面:

Actually, perl sigils don’t denote variable type – they denote conjugation – $ is ‘the’, @ is ‘these’, % is ‘map of’ or so – variable type is denoted via [] or {}. You can see this with:

my $foo = 'foo';
my @foo = ('zero', 'one', 'two');
my $second_foo = $foo[1];
my @first_and_third_foos = @foo[0,2];
my %foo = (key1 => 'value1', key2 => 'value2', key3 => 'value3');
my $key2_foo = $foo{key2};
my ($key1_foo, $key3_foo) = @foo{'key1','key3'};

so looking at the sigil when skimming perl code tells you what you’re going to -get- rather than what you’re operating on, pretty much.

This is, admittedly, really confusing until you get used to it, but once you -are- used to it it can be an extremely useful tool for absorbing information while skimming code.

You’re still perfectly entitled to hate it, of course, but it’s an interesting concept and I figure you might prefer to hate what’s -actually- going on rather than what you thought was going on :)

关于perl - Perl 中 `$this` 、 `@that` 和 `%those` 之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2731542/

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