Wierd result from hash array

Discussion in 'Perl Misc' started by Pacman, Sep 11, 2003.

  1. Pacman

    Pacman Guest

    I'm getting 'used' to hash arrays and am writing a perl script to
    backup my harddrive automatically. I couldn't figure out how to get
    the following code to work, so I must be making a mistake I can't see.

    Here's my expected result:

    foreaching on key one
    result: red/green

    instead I get the following:

    foreaching on key one
    two:three
    foreaching on key HASH(0x804c014)
    :

    #!/usr/bin/perl

    $BLAH = "one:red:green";

    %NADA = {};
    ($b1,@b2) = split(/:/,$BLAH);
    $NADA{$b1} = [@b2];

    foreach $k(keys %NADA) {
    print "foreaching on key $k\n";
    @x = @{$NADA{$k}};
    print "result: $x[0]/$x[1]\n";
    }

    Any help would be great...remove the nospam_ from the email address...

    D-
    Pacman, Sep 11, 2003
    #1
    1. Advertising

  2. Pacman

    Pacman Guest

    Made a slight mistake...the actual result I get is:

    foreaching on key one
    result: red/green
    foreaching on key HASH(0x804c014)
    :

    In article <110920031318586753%piercer@nospam_pacbell.net>, Pacman
    <piercer@nospam_pacbell.net> wrote:

    > I'm getting 'used' to hash arrays and am writing a perl script to
    > backup my harddrive automatically. I couldn't figure out how to get
    > the following code to work, so I must be making a mistake I can't see.
    >
    > Here's my expected result:
    >
    > foreaching on key one
    > result: red/green
    >
    > instead I get the following:
    >
    > foreaching on key one
    > two:three
    > foreaching on key HASH(0x804c014)
    > :
    >
    > #!/usr/bin/perl
    >
    > $BLAH = "one:red:green";
    >
    > %NADA = {};
    > ($b1,@b2) = split(/:/,$BLAH);
    > $NADA{$b1} = [@b2];
    >
    > foreach $k(keys %NADA) {
    > print "foreaching on key $k\n";
    > @x = @{$NADA{$k}};
    > print "result: $x[0]/$x[1]\n";
    > }
    >
    > Any help would be great...remove the nospam_ from the email address...
    >
    > D-


    --
    #############
    Imagination is more important than knowledge - A. Einstein
    Pacman, Sep 11, 2003
    #2
    1. Advertising

  3. Pacman

    Matija Papec Guest

    X-Ftn-To: Pacman

    Pacman <piercer@nospam_pacbell.net> wrote:
    >backup my harddrive automatically. I couldn't figure out how to get
    >the following code to work, so I must be making a mistake I can't see.
    >
    >Here's my expected result:
    >
    >foreaching on key one
    >result: red/green
    >
    >instead I get the following:
    >
    >foreaching on key one
    >two:three
    >foreaching on key HASH(0x804c014)


    use diagnostics;

    could tell you lot of useful things.


    --
    Matija
    Matija Papec, Sep 11, 2003
    #3
  4. "Pacman" <piercer@nospam_pacbell.net> wrote in message
    news:110920031318586753%piercer@nospam_pacbell.net...
    >
    >
    > I'm getting 'used' to hash arrays and am writing a perl script to
    > backup my harddrive automatically. I couldn't figure out how to get
    > the following code to work, so I must be making a mistake I can't see.
    >
    > Here's my expected result:
    >
    > foreaching on key one
    > result: red/green
    >
    > instead I get the following:
    >
    > foreaching on key one
    > two:three
    > foreaching on key HASH(0x804c014)
    > :
    >
    > #!/usr/bin/perl
    >
    > $BLAH = "one:red:green";
    >
    > %NADA = {};


    This line is your problem. You probably meant: %NADA = ();

    You would have discovered this if you had enable warnings (or diagnostics,
    as another poster indicated).

    jimk
    James E Keenan, Sep 11, 2003
    #4
    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. rp
    Replies:
    1
    Views:
    494
    red floyd
    Nov 10, 2011
  2. Michael Tan
    Replies:
    32
    Views:
    930
    Ara.T.Howard
    Jul 21, 2005
  3. Anthony Martinez
    Replies:
    4
    Views:
    258
    Robert Klemme
    Jun 11, 2007
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    596
    David A. Black
    Jul 2, 2008
  5. superfly2

    wierd Array of Hash result

    superfly2, Sep 12, 2003, in forum: Perl Misc
    Replies:
    1
    Views:
    76
    superfly2
    Sep 12, 2003
Loading...

Share This Page