问题描述
Perl中$this
,@that
和%those
有什么区别?
What is the difference between $this
, @that
, and %those
in Perl?
推荐答案
Perl信号有用的助记符是:
A useful mnemonic for Perl sigils are:
- $ calar
- @rray
- %ash
马特鳟鱼对我认为很有用,因此已在下面粘贴:
Matt Trout wrote a great comment on blog.fogus.me about Perl sigils which I think is useful so have pasted below:
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'};
因此,在浏览Perl代码时看着标记会告诉您您要去-get-而不是 比您的操作要多得多.
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中的$ this,@ that和%those有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!