Hi Andrew, On Sun, 12 Apr 2015 07:25:55 +0100 Andrew Solomon <and...@geekuni.com> wrote:
> Hi Frank > > I found the first one rather obscure, but they are equivalent. No - they are not exactly the same. See below: > 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; > } > However, with this program: < CODE > #!/usr/bin/perl use strict; use warnings; use Data::Dumper; { my $self; $self->{'DATA'} = { one => 'two', }; my $slot = $self->{'DATA'}; print "selfish self \n"; %{$self->{'DATA'}} = ( foo => 'bar' ); print Dumper $slot; } { my $self; $self->{'DATA'} = { one => 'two', }; my $slot = $self->{'DATA'}; print "selfless self \n"; $self->{'DATA'} = { foo => 'bar' }; print Dumper $slot; } < / CODE > I am getting this output: < SHELL > shlomif@telaviv1:~$ perl Test-hash-clear.pl selfish self $VAR1 = { 'foo' => 'bar' }; selfless self $VAR1 = { 'one' => 'two' }; shlomif@telaviv1:~$ < / SHELL > So as can be seen, they are not exactly equivalent. Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ Escape from GNU Autohell - http://www.shlomifish.org/open-source/anti/autohell/ <rindolf> If you repeat a scene 50k times, then the movie will have less entropy and will compress better. ( irc://irc.freenode.org/#perlcafe ) Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/