Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Return HashTable

Thread Tools

Return HashTable

BlackMage BlackMage is offline
Junior Member
Join Date: Jan 2010
Posts: 1
I am having problem with a Java program that calls a Perl/CGI Script, creates a hash and returns it. A simple example looks like this:

Perl Script:

sub createHash{

%hashTable = ();

$hashTable{"first"} = 1; # inserts a new hash table entry with key="first" and value=1
$hashTable{"second"} = 2; # new entry with key="second" and value=2

return %hashTable;

}#end createHash
Java Program

public void getHash(){
		HashMap hashmap=new HashMap();
		Vector params = new Vector();
		//Create Variables
    	try {
			XmlRpcClient xmlrpc = new XmlRpcClient(SERVER_URL);
			//Set Strings
        	        String methodName = "MyProgram.createHash";
        	System.out.println(xmlrpc.execute( methodName, params));
                //The line below is commented out because it throws an error
                //hashmap=(HashMap) xmlrpc.execute( methodName, params);
    	} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
		} catch (XmlRpcException e) {
			// TODO Auto-generated catch block
		} catch (IOException e) {
			// TODO Auto-generated catch block

	}//end class

The problems are this, when, I System.out.print the return hash created in Perl, is only prints out the last value. When I cast the return value to a Java Hash, it throws a string execption.

So how do I return a hash table or multiple values from a perl program?
Reply With Quote

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
Re: hashtable or map? (map inserts not behaving as I expect - and I cant find a decent simple example for hashtable) Kai-Uwe Bux C++ 1 12-21-2008 09:25 PM
what value does lack of return or empty "return;" return Greenhorn C Programming 15 03-06-2005 08:19 PM
Problem with hashTable Guillermo Perl 1 03-04-2004 12:43 PM
Get Hashtable Object Directly John E ASP .Net 1 10-08-2003 12:40 PM
vbc compilation fails when using Hashtable Jonathan Wolfson ASP .Net 1 06-27-2003 04:40 PM