I have a subroutine that returns a reference to a hash. I want to get the first key from that hash and assign it a variable after the subroutine returns. Right now, I am doing this and this works but I think there should a smarter/easier way
my $hash = get_value(); # calling my subroutine here which returns a reference to a hash
foreach my $keys (keys %{$hash}) {
my $test_variable = $keys; # Assigning the first key to variable
# check if variable is not empty and exit the loop
if (!$test_variable) {
last;
}
}
all you need is: