Wierd result from hash array

P

Pacman

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-
 
P

Pacman

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

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

Pacman said:
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-
 
M

Matija Papec

X-Ftn-To: Pacman

Pacman said:
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.
 
J

James E Keenan

Pacman said:
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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top