Return HashTable

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

  1. BlackMage

    BlackMage

    Joined:
    Jan 17, 2010
    Messages:
    1
    Likes Received:
    0
    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 (Text):


    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 (Text):


    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. Advertisements

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. PvdK
    Replies:
    0
    Views:
    3,234
  2. wl
    Replies:
    2
    Views:
    874
    Dimitri Maziuk
    Mar 5, 2004
  3. Ganesh Gella
    Replies:
    4
    Views:
    533
    Stuart Gerchick
    Nov 12, 2004
  4. Seong-Kook Shin
    Replies:
    1
    Views:
    798
    Richard Bos
    Jun 18, 2004
  5. Steve Knight
    Replies:
    2
    Views:
    1,187
    Steve Knight
    Oct 10, 2003
  6. Joseph Garvin

    How "return" no return ?

    Joseph Garvin, May 12, 2005, in forum: Python
    Replies:
    9
    Views:
    530
    Jeff Epler
    May 13, 2005
  7. Carl
    Replies:
    21
    Views:
    1,554
    Patricia Shanahan
    Aug 24, 2006
  8. Greenhorn
    Replies:
    15
    Views:
    1,253
    Keith Thompson
    Mar 6, 2005
Loading...