Reference and assignment question



I was exploring why something didn't work the way I expected using
DBM::Deep (0.983 from ActiveState) and came upon some behavior I don't
understand. I think it has something to do with using bless or tie,
but I have not used either yet.

Here is my code. My questions are in the comments for the last 4 lines:
---------------------------------------
#!/perl/bin/perl
use strict;
use warnings;

use DBM::Deep;
use Data::Dumper;

unlink("test.db");
my $database = DBM::Deep->new(
file => "test.db",
locking => 1,
autoflush => 1 );

# Test array that contains a hash reference as an element
my @array = ("Mac Address", "PCNAME", 1, 1187000400, { 'bob' => 23,
'alice' => 20 });
print("\@array\n", Dumper(\@array)); # Shows the contents of the
array, with no blessed references and nothing tied to the DBM::Deep
database

$database->{141} = \@array; # Assigns the array reference as a value
of the DBM::Deep database hash
print("\@array\n", Dumper(\@array)); # Now the original array's
internal hash is tied or blessed or something to the database

my $temp = $database->{141}->export; # Export should return a
reference to an array in which the internal hash is not tied to the
database anymore
print("\$temp\n", Dumper($temp)); # Dumper shows no tied or blessed
hash; seems like it worked.

my @new_array = @{ $temp }; # Dereferencing the array reference to
reconstitute the array.
print("\@new_array\n", Dumper(\@new_array)); # The new array's hash
reference is normal.

@array = @{ $temp }; # Assigning the array reference to the original
array variable.. should work fine.
print("\@array\n", Dumper(\@array)); # This prints a hash reference
that is still tied to the database. WTF?

my @array = @{ $temp }; # Assigning the array reference to the
original array variable but redeclaring it using my.
print("\@array\n", Dumper(\@array)); # This works... Why is
redeclaring the variable important? Why doesn't the reassignment
work?
-------------------------------------------

Thanks for any enlightenment...
Roman
.



Relevant Pages

  • RE: Array de-referencing problem
    ... But I guess it's better to use an array reference? ... Conversation: Array de-referencing problem ... The values of a hash can only be scalars! ...
    (perl.beginners)
  • Re: Complex Objects in Perl
    ... > sub-object is made up of a number of different objects and an array of an ... Objects in Perl are implemented as a reference to an anonymous hash. ...
    (comp.lang.perl)
  • Re: complex data structure
    ... reference to an anonymous one-key hash. ... store, just put them in the array: ... stores a reference to an anonymous 4-element array into scalar variable ...
    (comp.lang.perl)
  • Re: Accessing hash of arrays?
    ... I want to archive to hash indexed by the target folder: ... I am not trying to slice an array. ... to be a reference to an array. ...
    (perl.beginners)
  • Re: printing on new lines
    ... possible to print each reference on a different line. ... case opt ... For readability and reusability you should extract the database making ... # this makes an array of arrays, ...
    (comp.lang.ruby)