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.
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?
Try:
my $main_server = $self->{source_env}->{server}->[0];
Try $server_ref->[0], it should work.
精彩评论