gpt4 book ai didi

arrays - 我不明白这个 Perl 语法,有人知道吗?

转载 作者:行者123 更新时间:2023-12-02 02:54:32 25 4
gpt4 key购买 nike

我从 Perl 插件中得到了这部分。我不明白它有什么作用。它是关联数组的数组吗?如果是的话,那不是应该以@开头吗?谁能解释一下这个问题?

my $arguments =
[ { 'name' => "process_exp",
'desc' => "{BasePlugin.process_exp}",
'type' => "regexp",
'deft' => &get_default_process_exp(),
'reqd' => "no" },
{ 'name' => "assoc_images",
'desc' => "{MP4Plugin.assoc_images}",
'type' => "flag",
'deft' => "",
'reqd' => "no" },
{ 'name' => "applet_metadata",
'desc' => "{MP4Plugin.applet_metadata}",
'type' => "flag",
'deft' => "" },
{ 'name' => "metadata_fields",
'desc' => "{MP4Plugin.metadata_fields}",
'type' => "string",
'deft' => "Title,Artist,Genre" },
{ 'name' => "file_rename_method",
'desc' => "{BasePlugin.file_rename_method}",
'type' => "enum",
'deft' => &get_default_file_rename_method(), # by default rename imported files and assoc files using this encoding
'list' => $BasePlugin::file_rename_method_list,
'reqd' => "no"
} ];

最佳答案

正如 Bwmat 所说,它是对哈希引用数组的引用。阅读

$ man perlref

$ man perlreftut     # this is a bit more straightforward

如果您想了解更多有关引用的信息。

顺便说一句,在 Perl 中你可以这样做:

@array = ( 1, 2 );          # declare an array
$array_reference = \@array; # take the reference to that array
$array_reference->[0] = 2; # overwrite 1st position of @array

$numbers = [ 3, 4 ]; # this is another valid array ref declaration. Note [ ] instead of ( )

哈希值也会发生同样的情况。

顺便说一句,在 Perl 中你可以这样做:

%hash = ( foo => 1, bar => 2 );
$hash_reference = \%hash;
$hash_reference->{foo} = 2;

$langs = { perl => 'cool', php => 'ugly' }; # this is another valid hash ref declaration. Note { } instead of ( )

而且...是的,您可以取消引用这些引用。

%{ $hash_reference }

将被视为散列,因此如果您想打印上面的$langs的键,您可以这样做:

print $_, "\n" foreach ( keys %{ $langs } );

要取消引用数组引用,请使用 @{ } 而不是 %{ }。甚至 sub 也可以取消引用。

sub foo
{
print "hello world\n";
}

my %hash = ( call => \&foo );

&{ $hash{call} }; # this allows you to call the sub foo

关于arrays - 我不明白这个 Perl 语法,有人知道吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8163785/

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