Stuck with perl Geocoding package - Help!

Discussion in 'Programming' started by balaa_uk, Sep 11, 2006.

  1. #1
    balaa_uk, Sep 11, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    The directory will be defined by the URL or the file which calls the included file. For instance: http://localhost/perl/geocodews.pl wants to see the perl source file located in a directory named perl which is located in the top level of web server. If your web server's top level directory is: /var/www then the file needs to be in the directory /var/www/perl
     
    clancey, Sep 11, 2006 IP
  3. balaa_uk

    balaa_uk Peon

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thank you very much. I'll give it a try.
     
    balaa_uk, Sep 11, 2006 IP
  4. balaa_uk

    balaa_uk Peon

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi, this worked very well. Is it possible to call this perl script from php and use the returned values ( this perl script accepts US address and returns longitude and latitude)
     
    balaa_uk, Sep 12, 2006 IP
  5. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #5
    The only way I have been able to get that to work is to call the perl script using the exec function and then parsing the results for use by the PHP program. Something like:

    
    $args = "US address";
    $result = exec( "perl /var/www/perl/geocodews.pl " . $args);
    list($long, $lat) = split( "-DELIM-", $result);
    
    Code (markup):
    Change -DELIM- to whatever delimiter the perl script uses to separate the values.

    PHP is making a command line call to the script and retrieving the result. The perl program needs to be able to retrieve the information from the argument string. I use shift. But, if the address has spaces, this might be an issue.

    The perl program must be doing some kind of database call. Why not work that out in PHP?
     
    clancey, Sep 12, 2006 IP
  6. balaa_uk

    balaa_uk Peon

    Messages:
    94
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    This looks like a good idea. But how do I execute a perl code that lives in another domain.

    for ex. GEO DB and geocodeclient.pl lives in my home system under domain 'A.com'. The php script that requires the output of this perl script lives in 'B.com'. Hence i can't use an absolute path such as 'perl /var/www/cgi-bin/geocodews.pl'. Can I use 'perl www.A.com/cgi-bin/geocodeclient.pl'.
     
    balaa_uk, Sep 12, 2006 IP
  7. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #7
    No. . . . but if you control the output of the perl script then you could call the script from within PHP with the proper parameters in the URL and capture the results locally.

    However, if the script is not under your control, you may get messed up by security measures intended to prevent the perl script from being enslaved.

    This approach works with machines on separate IPs.

    Your php program:

    
    <?php
    
    $story = file( 'http://www.B.com/cgi-bin/test.pl?this-is-my-query');
    $paras = count($story);
    $line = "";
    for ($x = 0; $x < $paras; $x++) { $line .= $story[$x]; }
    
    echo "test.pl said == > $line<br>";
    ?>
    
    Code (markup):
    Your perl program -- test.pl
    
    #!/usr/bin/perl
    
    $query = $ENV{"QUERY_STRING"};
    
    print "Content-type: text/html\n\n";
    print "query is $query";
    
    Code (markup):
    Here, perl simply returns the query -- the information after the question mark in the URL. But, it could return anything you need. PHP views this as just another file, so you can do anything you need with the generated data.
     
    clancey, Sep 12, 2006 IP