Any difference between ref to hash and ref to anonymous hash?

J

Justin C

Sometimes I do this:
sub foo {
my %h = (
k1 => 1,
k2 => 2,
);
return \%h;
}

Other times I do this:
sub bar {
my $h = {
k1 => 1,
k2 => 2,
};
return $h;
}

Is there any difference between $x and $y if I:
my $x = foo();
my $y = bar();

Using YAML qw/Dump/ says not, but is there anything I should be aware
of when using either form? Is there a "best practice" that says use
one of them over the other?


Justin.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top