why doesn't my dbm file save my data?

Discussion in 'Perl Misc' started by jaialai technology, Dec 4, 2010.

  1. The code below is saved to a file called, say, temp.pl.
    I run $perl temp.pl a b
    and then I immediately run
    $perl temp.pl c d
    On this second run I expect to see the key 'a' of my first run but I
    do not.
    Why?
    I am not getting any errors and the
    associated db files are in /tmp
    -rw-r--r-- 2 jt jt 12306 2010-12-04 14:53 test_db.dir
    -rw-r--r-- 2 jt jt 12306 2010-12-04 14:53 test_db.pag


    ----
    temp.pl
    ----
    my %TEST_DATA;
    dbmopen(%TEST_DATA,"/tmp/test_db",0666);
    foreach my $key (keys %TEST_DATA){
    print "$key\n";
    }
    $TEST_DATA[$ARGV[0]]=$ARGV[1];
    dbmclose(%TEST_DATA);
    jaialai technology, Dec 4, 2010
    #1
    1. Advertising

  2. Nevermind. I see my error.
    Silly mistake.
    $TEST_DATA[$ARGV[0]]=$ARGV[1];
    should read
    $TEST_DATA{$ARGV[0]}=$ARGV[1];
    jaialai technology, Dec 4, 2010
    #2
    1. Advertising

  3. jaialai technology

    Marc Girod Guest

    On Dec 4, 8:22 pm, jaialai technology <>
    wrote:

    > Why?


    Because you do not write into your hash, but into a @TEST_DATA array:

    > $TEST_DATA[$ARGV[0]]=$ARGV[1];


    use strict; would have told you.

    $TEST_DATA{$ARGV[0]}=$ARGV[1];

    Marc
    Marc Girod, Dec 4, 2010
    #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. Matt Johnson
    Replies:
    0
    Views:
    1,273
    Matt Johnson
    Aug 8, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    880
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    1,850
    Smokey Grindel
    Dec 2, 2006
  4. Akira Kitada
    Replies:
    0
    Views:
    207
    Akira Kitada
    Apr 9, 2009
  5. Akira Kitada
    Replies:
    3
    Views:
    275
    Akira Kitada
    Apr 11, 2009
Loading...

Share This Page