PDA

View Full Version : howto perl script and datastore



vito_huang
27 Sep 2007, 3:43 AM
i know this is a bit unrelative to extjs stuff, but i just wondering how to write a perl script that can directly call from datastore's url link, because i tried to point datastore's url a perl script which just simple print out a xml file, and that doesn't work, however when i point datastore's url directly to the xml file everything was fine.

so now i have to use a perl script to generate a xml file and get datastore's url point to the xml file, and i just wondering how to write a perl script that will work when the datastore's url point to it, because i don't want to generate a xml file everytime(and that will waste space as well).

i need using perl to do it, because i need information from perl module that other language can't do it ( is about lsf job information). so i can't use php for it

thanks,


Vito

evant
27 Sep 2007, 3:43 AM
You're better off asking this type of question in a perl forum somewhere.

seanfell
27 Sep 2007, 6:17 AM
Your in luck..
I use perl for most of my backend scripts.

A really simple script would be


#! /usr/bin/perl

XMLHeader();
print "<MYXML><NODE>This is some Text</NODE></MYXML>";


sub XMLHeader {
print "Content-Type: text/xml; charset=UTF-8\n";
print "Cache-Control: no-cache\n";
print "\n";
print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}

sub HTMLHeader {
#print "Content-Type: text/html; charset=UTF-8\n";
print "Content-Type: text/html; charset=iso-8859-1\n";
print "Cache-Control: no-cache\n";
print "\n";
# print "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
}

if you save this as say 'test.cgi' (if on UNIX ensure you set permissions to make it executable) and then

1) Ensure it runs ok from the command line (EG: perl test.cgi')
2) Put it into the 'cgi-bin' (or equivalent) of your Webserver and in a browser trying to execute it directly EG. http://<your-site-url-here>/cgi-bin/test.cgi and check this runs ok

If you get this far ok then plugging the URL into Ext data store to get the XML should work ok. Processing that XML within EXT however is another question.... (which i'm sure you'll ask..)

hope this helps

vito_huang
28 Sep 2007, 1:31 AM
thanks m8, that's exactly what i am looking for(change content type to text/html to text/xml - god i am stupid, why i haven't think of that :().

notjoshing
28 Sep 2007, 5:22 AM
I'm a Perl developer using Ext as well. I suggest taking a look at some of the templating modules, such as CGI::Application, and some of the JSON modules, such as JSON:: DWIW.

Josh

vito_huang
4 Oct 2007, 1:36 AM
because i try to install json modules, but for some reasons i can't install them, so i just wondering what would the http header shoud be for passing json data back to a script?

Gilant
4 Oct 2007, 7:51 AM
because i try to install json modules, but for some reasons i can't install them,

Without knowing what platform you are on or the error you got it is hard to say why you couldn't. And that problem would certainly be better solved on a Perl forum, IRC channel or mailing list (and there are plenty for all levels). But as a quick shot in the dark, on a Linux/Unix platform where you don't have root permissions (a very common case) you can install the module to any directory you have permission to write to by providing the PREFIX argument to Makefile.PL.

% perl Makefile.PL PREFIX=/home/username/perl_lib

And then you can add use lib "/home/username/perl_lib";

To you CGI (or set the PERL5LIB environment variable in your webserver) so your code can find you personal module tree. See the docs (man ExtUtils::MakeMaker) for more information.


so i just wondering what would the http header shoud be for passing json data back to a script?

'application/json'

HTH!