MiN*_*EaK 3 arrays perl reference perl-data-structures
我从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"
} ];
Run Code Online (Sandbox Code Playgroud)
正如Bwmat所说,它是对一组哈希引用的引用.读
$ man perlref
Run Code Online (Sandbox Code Playgroud)
要么
$ man perlreftut # this is a bit more straightforward
Run Code Online (Sandbox Code Playgroud)
如果您想了解更多有关参考文献的信息.
顺便说一句,在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 ( )
Run Code Online (Sandbox Code Playgroud)
哈希也会发生同样的事情.
顺便说一句,在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 ( )
Run Code Online (Sandbox Code Playgroud)
并且......是的,您可以取消引用这些引用.
%{ $hash_reference }
Run Code Online (Sandbox Code Playgroud)
将被视为哈希,所以如果你想打印$langs上面的键,你可以这样做:
print $_, "\n" foreach ( keys %{ $langs } );
Run Code Online (Sandbox Code Playgroud)
要取消引用数组ref @{ }而不是%{ }.甚至sub可以被解除引用.
sub foo
{
print "hello world\n";
}
my %hash = ( call => \&foo );
&{ $hash{call} }; # this allows you to call the sub foo
Run Code Online (Sandbox Code Playgroud)