On Apr 12, 2015 8:06 AM, "Shawn H Corey" <shawnhco...@gmail.com> wrote: > > On Sat, 11 Apr 2015 21:20:22 -0700 > SSC_perl <p...@surfshopcart.com> wrote: > > > Could someone please explain the difference between: > > > > %{$self->{'DATA'}} = () } > > %{ $self->{'DATA'} } = (); > > > > > and > > > > $self->{'DATA'} = {} > > > > I was told that they are equivalent, but they're not. One > > works and the other doesn't, so they must be different. Here's the > > context: > > No, they are not the exact same, as this snippet of code shows: > > my $self = { DATA => 1 }; > %{ $self->{'DATA'} } = (); > > If $self->{DATA} does not exist, then they are the same because Perl > does autovivification. To get the first one to behave like the second, > you should delete $self->{DATA} > > delete( $self->{DATA} ); > %{ $self->{'DATA'} } = (); >
Right, you can change the example to make it different but the examples as given are equivalent. Here's another test for you : my ($n, $m); print "ok" if (ref(%{$n->{a}} = ()) eq ref($m->{a} = {})); You could use something like Test::Deep to remove all doubt, but...