I'm confused by reference to reference in my code

S

surf

In a package I have this, I then use DB_File to tie
%data to a file:


package persist;

%data;

....
<various code>
....

---------------------------------
In another file I have the following code section.
I get a reference to the hash in the persist
package, put a hash reference into it
but when I take it back out it's no longer
a reference. What could I have done wrong ?


$typ = ref($r_session);
print("T:$typ <BR>\n");
$rf = \%persist::data;
$rf->{$app_id} = $r_session;
$myref = $rf->{$app_id};

$typ2 = ref($myref);
$typ3 = ref($rf);

print("T2:$typ2 <BR> \n");
print("T3:$typ3 <BR> \n");



this code prints:

T:HASH
T2:
T3:HASH
 
X

xhoster

surf said:
In a package I have this, I then use DB_File to tie
%data to a file:

package persist;

%data;

...
<various code>
...

---------------------------------
In another file I have the following code section.
I get a reference to the hash in the persist
package, put a hash reference into it
but when I take it back out it's no longer
a reference. What could I have done wrong ?

You tried to store multi-level data into a DB_File, which inherently
cannot store multi-level data.

Xho
 
T

Tad McClellan

surf said:
In a package I have this, I then use DB_File to tie
%data to a file:


package persist;


Lowercase package names are, by convention, reserved for pragmas.

package Persist;



You should always enable strict (and warnings) when developing Perl code.

use warnings;
use strict;
my %data;

What could I have done wrong ?


Failed to check the Perl FAQ before posting to the Perl newsgroup:

perldoc -q persist

How do I keep persistent data across program calls?

perldoc -q copy

How do I print out or copy a recursive data structure?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top