I'm confused by reference to reference in my code

Discussion in 'Perl Misc' started by surf, Feb 6, 2006.

  1. surf

    surf Guest

    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
    surf, Feb 6, 2006
    #1
    1. Advertising

  2. surf

    Guest

    "surf" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Feb 7, 2006
    #2
    1. Advertising

  3. surf <> wrote:
    >
    > 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;


    > %data;



    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?


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 7, 2006
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. G. Dean Blake

    Generated Code Confused

    G. Dean Blake, Jun 12, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    341
    John Saunders
    Jun 13, 2004
  2. Dave Smithz
    Replies:
    4
    Views:
    343
    Dave Smithz
    Oct 27, 2004
  3. Steve Richter

    confused about null reference compile error

    Steve Richter, Apr 26, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    3,099
    Steve Richter
    Apr 26, 2005
  4. David
    Replies:
    3
    Views:
    327
    David
    Dec 18, 2004
  5. Replies:
    1
    Views:
    413
    Eric Sosman
    Feb 12, 2008
Loading...

Share This Page