Hi Frank I found the first one rather obscure, but they are equivalent. To prove this, Data::Dumper is my friend:
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; { my $self; print "selfish self \n"; %{$self->{'DATA'}} = ( foo => 'bar' ); print Dumper $self; } { my $self; print "selfless self \n"; $self->{'DATA'} = { foo => 'bar' }; print Dumper $self; } Hope that helps, Andrew On Sun, Apr 12, 2015 at 7:06 AM, shawn wilson <ag4ve...@gmail.com> wrote: > > On Apr 12, 2015 12:23 AM, "SSC_perl" <p...@surfshopcart.com> wrote: > > > > Could someone please explain the difference between: > > > > %{$self->{'DATA'}} = () } > > > > The hashref of key "DATA" equals an empty list. The trailing bracket is > the end of the else block. $self is also probably blessed (an object). > > ref($self->{DATA}) eq 'HASH' > > > and > > > > $self->{'DATA'} = {} > > > > Same > > > 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: > > > > -------------------- > > > > sub empty_db { > > my $self = shift; > > if ($self->{'USEDBM'} eq 'sql') { > > $self->{'SQL'}->do("DELETE from $self->{'DB'}") or > $self->{'ERRMSG'} .= $DBI::errstr and return; > > } > > else { %{$self->{'DATA'}} = () } > > # else { $self->{'DATA'} = {} } # This does nothing > > } > > > > IDK where this is from, but I'd question the wisdom of running this > code... > -- Andrew Solomon Mentor@Geekuni http://geekuni.com/ http://www.linkedin.com/in/asolomon