vennirajan has asked for the wisdom of the Perl Monks concerning the following question:
I have written a piece of code to produce a sort of "Cartesian Product" of the data structure. But the code produces the strange output. Can any one tell me what is happening ?
my %data = ( "one" , 1, "two",2,"three",3,"four",4,"five",5,"six",6,"s +even",7,"eight",8,"nine",9); my %newData = (); while (my ($key1,$val1) = each(%data)) { if (my ($key,$value) = each(%data)) { $newData{$key1,$key} = "$val1$;$value"; } else { last; } } map { print "$_ : $newData{$_}\n";} keys %newData ;
Thanks in advance.fiveseven : 57 nineeight : 98 twoone : 21 threesix : 36
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: What is wrong with the code ?
by japhy (Canon) on Jan 18, 2006 at 08:12 UTC | |
by vennirajan (Friar) on Jan 18, 2006 at 08:14 UTC | |
by Anonymous Monk on Jan 18, 2006 at 08:27 UTC | |
|
Re: What is wrong with the code ?
by GrandFather (Saint) on Jan 18, 2006 at 08:15 UTC | |
|
Re: What is wrong with the code ?
by NetWallah (Canon) on Jan 18, 2006 at 17:53 UTC |