Assuming I use , say, the following relation
sub _relation {
+{
player1 => 0,
player2 => 1,
player3 => 0,
},
;
}
This subroutine returns a hash reference (pointer to a hash.) Curly braces used in this fashion construct an anonymous hash and return a reference to it.
Assuming you call the subroutine something like this:
my $results = _relation();
You would access the elements using the ->
dereferencing operator:
$results->{player1} # 0
$results->{player2} # 1
If you want to copy the anonymous hash into a named one, you can dereference the entire thing at once with
my %regular_hash = %$results;
See the Perl References Tutorial for more.
friedo's answer is correct. When trying to understand data structures, it's helpful to use Data::Dumper.
use Data::Dumper;
print Dumper(_relation());
The {}'s in the output show this is an anonymous hash:
$VAR1 = {
'player3' => 0,
'player2' => 1,
'player1' => 0
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With