[英]Perl dereferencing array for specific value
So, in Perl, I have an array within an object (so, a reference to an array), and I want to find the first value of that array. 因此,在Perl中,我在一个对象内有一个数组(因此是对数组的引用),我想找到该数组的第一个值。
I find myself using code like the following quite often: 我发现自己经常使用以下代码:
my $server_ref = $self->{source_env}->{server};
my @servers = @$server_ref;
my $main_server = $servers[0];
That works, but I'm sure I could do this without all the intermediate lines and variables. 那行得通,但是我确定我可以在没有所有中间行和变量的情况下做到这一点。
Can someone help me with the syntax? 有人可以帮我语法吗?
尝试:
my $main_server = $self->{source_env}->{server}->[0];
尝试$ server_ref-> [0],它应该可以工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.