Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Multidimesional hashs in Perl, C++, C# and Perl6

by TedYoung (Deacon)
on May 04, 2007 at 13:51 UTC ( [id://613569]=note: print w/replies, xml ) Need Help??


in reply to Multidimesional hashs in Perl, C++, C# and Perl6

I'll add some java to the mix:

package Foo; import java.util.HashMap; public class Bar { public static void main(String... args) { HashMap<String, HashMap<String, Integer>> map = new HashMap<Stri +ng, HashMap<String, Integer>>(); map.put("A", new HashMap<String, Integer>()); map.get("A").put("A", 1); map.get("A").put("B", 2); map.put("B", new HashMap<String, Integer>()); map.get("B").put("A", 4); map.get("B").put("B", 8); for(String k: map.get("B").keySet()) { System.out.println(k + " - " + map.get("B").get(k)); } } }

Java would be the language I use most after Perl. When using Java, I often think about how much I miss the first class support for lists and hashes that we have in Perl. But, I find that when I don't have that first class support, I write things differently anyhow. If it is harder to make and use a hash, I won't use a hash as often.

That being said, I really love Java's hierarchy of collections. There are many powerful types of lists and hashes, and Generics really simplify things.

Ted Young

($$<<$$=>$$<=>$$<=$$>>$$) always returns 1. :-)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://613569]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2024-03-28 10:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found