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

Discussion in 'Perl Misc' started by Justin C, Oct 7, 2013.

  1. Justin C

    Justin C Guest

    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.

    --
    Justin C, by the sea.
    Justin C, Oct 7, 2013
    #1
    1. Advertising

  2. Justin C

    Justin C Guest

    On 2013-10-07, Ben Morrow <> wrote:
    >
    > Quoth Justin C <>:


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

    >
    > No.
    >
    > Ben


    Nice and concise. Thank you, Ben.


    Justin.

    --
    Justin C, by the sea.
    Justin C, Oct 7, 2013
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,115
  2. Reporter
    Replies:
    3
    Views:
    470
    Mike Schilling
    May 12, 2007
  3. rmn190
    Replies:
    0
    Views:
    900
    rmn190
    Dec 31, 2007
  4. Replies:
    1
    Views:
    218
  5. J Krugman
    Replies:
    17
    Views:
    230
    Anno Siegel
    Mar 15, 2005
Loading...

Share This Page