princepawn has asked for the wisdom of the Perl Monks concerning the following question:

I am lost. I thought anonymous hashes and hash references were the same thing. But, maybe this is a similar misconception to equating arrays and lists? In other words:
%hash = ( 1 => 2 ); $x = { x => 'y' } $z = \%hash;
$x is a reference to an anonymous hash. $z is a reference to a hash.

Can we parallel this with lists/arrays in some way? How can we do the following?

  1. Reference to anonymous list
  2. Reference to array
  3. Reference to list
  • Comment on anonymous hash versus hash reference and their parallels in arrays
  • Download Code

Replies are listed 'Best First'.
Re: anonymous hash versus hash reference and their parallels in arrays
by davorg (Chancellor) on Aug 21, 2000 at 17:15 UTC

    You can't take a reference to a list as there isn't a single 'thing' to take a reference to. You can, however, take a reference to an anonymous array. To mirror your examples using arrays you'd do something like this:

    @array = ( 1 .. 10 ); $x = [ 'a' .. 'z' ]; $z = \@array;

    $x is a reference to an anonymous array. $z is a reference to an array.

    --
    <http://www.dave.org.uk>

    European Perl Conference - Sept 22/24 2000, ICA, London
    <http://www.yapc.org/Europe/>
RE (tilly) 1: anonymous hash versus hash reference and their parallels in arrays
by tilly (Archbishop) on Aug 21, 2000 at 17:55 UTC
    Arrays truly are different from lists. See Arrays are not lists for some commentary on the difference.