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("[EMAIL PROTECTED]", Dumper([EMAIL PROTECTED]));  # Shows the contents of 
the
array, with no blessed references and nothing tied to the DBM::Deep
database

$database->{141} = [EMAIL PROTECTED];   # Assigns the array reference as a value
of the DBM::Deep database hash
print("[EMAIL PROTECTED]", Dumper([EMAIL PROTECTED]));  # 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("[EMAIL PROTECTED]", Dumper([EMAIL PROTECTED]));  # The new array's hash
reference is normal.

@array = @{ $temp };    # Assigning the array reference to the original
array variable.. should work fine.
print("[EMAIL PROTECTED]", Dumper([EMAIL PROTECTED]));  # 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("[EMAIL PROTECTED]", Dumper([EMAIL PROTECTED]));  # This works...  Why is
redeclaring the variable important?  Why doesn't the reassignment
work?
-------------------------------------------

Thanks for any enlightenment...
Roman

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to