Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Wierd result from hash array

Reply
Thread Tools

Wierd result from hash array

 
 
Pacman
Guest
Posts: n/a
 
      09-11-2003


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-
 
Reply With Quote
 
 
 
 
Pacman
Guest
Posts: n/a
 
      09-11-2003

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
 
Reply With Quote
 
 
 
 
Matija Papec
Guest
Posts: n/a
 
      09-11-2003
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
 
Reply With Quote
 
James E Keenan
Guest
Posts: n/a
 
      09-11-2003

"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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hash of hash of hash of hash in c++ rp C++ 1 11-10-2011 04:45 PM
Hash#select returns an array but Hash#reject returns a hash... Srijayanth Sridhar Ruby 19 07-02-2008 12:49 PM
Array#inject to create a hash versus Hash[*array.collect{}.flatten] -- Speed, segfault Anthony Martinez Ruby 4 06-11-2007 08:16 AM
1. Ruby result: 101 seconds , 2. Java result:9.8 seconds, 3. Perl result:62 seconds Michael Tan Ruby 32 07-21-2005 03:23 PM
wierd Array of Hash result superfly2 Perl Misc 1 09-12-2003 07:38 PM



Advertisments