Return HashTable

Discussion in 'Perl' started by BlackMage, Jan 17, 2010.

  1. BlackMage

    BlackMage

    Joined:
    Jan 17, 2010
    Messages:
    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:

    Code:
    
    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

    Code:
    
    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
    			e.printStackTrace();
    		} catch (XmlRpcException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
        	
        	
        	
    
    	}//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?
    BlackMage, Jan 17, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guillermo

    Problem with hashTable

    Guillermo, Mar 4, 2004, in forum: Perl
    Replies:
    1
    Views:
    605
    Gunnar Hjalmarsson
    Mar 4, 2004
  2. Jonathan Wolfson

    vbc compilation fails when using Hashtable

    Jonathan Wolfson, Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    544
    Tu-Thach
    Jun 27, 2003
  3. John E

    Get Hashtable Object Directly

    John E, Oct 8, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,320
    Nicholas Paldino [.NET/C# MVP]
    Oct 8, 2003
  4. diya

    Type Hashtable not defined

    diya, Oct 31, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,771
    Nicole Calinoiu
    Oct 31, 2003
  5. Greenhorn
    Replies:
    15
    Views:
    814
    Keith Thompson
    Mar 6, 2005
Loading...

Share This Page