Reference and assignment question
- From: romandas@xxxxxxxxx (Roman Daszczyszak)
- Date: Tue, 29 Jan 2008 17:20:26 +0100
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
.
- Prev by Date: Re: groups of values from an array
- Next by Date: Re: groups of values from an array
- Previous by thread: groups of values from an array
- Next by thread: JVM thread monitoring
- Index(es):
Relevant Pages
|