Wierd result from hash array

Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Wierd result from hash array



    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 Guest

  2. Similar Questions and Discussions

    1. Wierd query result on MySQL 5 system
      I have the following table (complete with sample data). When I run the query below on a mysql 4.1.14 system, the only row returned is row 4 as...
    2. Updating an array within a hash
      Hi Everybdy, I am stuck in a problem for which I need your help. My problem spins around adding an element in an array within a hash. I have a...
    3. hash of hash of array slices
      This works Foreach ( @{$hash{$key1}{$key2}} ) This does note Foreach ( @{($hash{$key1}{$key2})} ) This gives me this error .... Can't...
    4. adding an array as a hash value
      Hi Dermot. Dermot Paikkos wrote: And use warnings; These variables need to have better names so that it's more
    5. wierd Array of Hash result
      I have constructed an array of hashes (pointers to hash elements) and I have the following problem when I foreach or for loop through the array and...
  3. #2

    Default Re: Wierd result from hash array


    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 Guest

  4. #3

    Default Re: Wierd result from hash array

    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 Guest

  5. #4

    Default Re: Wierd result from hash array


    "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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139