in reply to Re: Perl Script to populate Dropdown box from XML Attributes
in thread Perl Script to populate Dropdown box from XML Attributes

Client-side server has Active perl installed in it, so we don't have any problem running Perl Script on the browser. So can you help me achieve this with Perl Script? Thanks!

  • Comment on Re^2: Perl Script to populate Dropdown box from XML Attributes

Replies are listed 'Best First'.
Re^3: Perl Script to populate Dropdown box from XML Attributes
by Corion (Patriarch) on Nov 23, 2016 at 08:18 UTC
    my $xp = XML::XPath->new(filename => 'State.xml');

    I doubt that the file State.xml is available on the client, where the code runs.

    Or even if that file is on the client, you will need to specify the full path to it, and even then I doubt that the Internet Explorer scripting sandbox will easily allow access to the file.

      The file State.xml is present in the same folder as the HTML. I did change the path as below:

      my $xp = XML::XPATH->new(filename => 'D://New folder//State.xml');

      But it did not work. Can you help to do it?

        That's not how HTTP resources work. I recommend you learn about HTTP, HTML and how it matters where a script is run.

        I'm surprised anyone is trying to use PerlScript in production anymore. The documentation says:

        "Client-side Perlscript should only be used if you can control the configuration of the computers on which it will be run. If your goal is to build an application that will be used by a large number of users, server-side PerlScript is considerably more practical."

Re^3: Perl Script to populate Dropdown box from XML Attributes
by soonix (Chancellor) on Nov 24, 2016 at 11:32 UTC
    Client-side Server
    … sounds like an Oxymoron to me (except if you're using Terminal Servers or some such). Perhaps you should elaborate on your setup.

    PerlScript documentation says it's an optional component, so, even if ActivePerl is installed, PerlScript might not. That documentation page also contains an example "Client-side PerlScript". Does that work?

      Its not a terminal server. But it has Perl Script on it. "perl -v" on cmd brings up this:

      This is perl, v5.6.1 built for MSWin32-x86-multi-thread (with 1 registered patch, see perl -V for more detail)

      Copyright 1987-2001, Larry Wall

      Binary build 631 provided by ActiveState Tool Corp. http://www.ActiveState.com Built 17:16:22 Jan 2 2002

      Perl may be copied only under the terms of either the Artistic License or the GNU General Public License, which may be found in the Perl 5 source kit.

      Complete documentation for Perl, including FAQ lists, should be found on this system using `man perl' or `perldoc perl'. If you have access to the Internet, point your browser at http://www.perl.com/, the Perl Home Page.

      I have gone through the Client-side PerlScript example:

      <html> <head> <title>PerlScript Hello World!</title> </head> <body bgcolor="#ffffff"> <h2>PerlScript Hello world!</h2> <script language="PerlScript"> $window->document->write('Hello world!'); </script> </body> </html>

      This works with the below meta tag in the <head> section

      <html> <head> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <title>PerlScript Hello World!</title> </head> <body bgcolor="#ffffff"> <h2>PerlScript Hello world!</h2> <script language="PerlScript"> $window->document->write('Hello world!'); </script> </body> </html>

      The above code works fine but I am asked not to use meta tag work around. And even after using meta tag, my original code is not working.

      <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>demo of dropdown list using xml element data in PerlScript</ti +tle> </head> <body> <SELECT id="STATE" style="WIDTH: 100px; "> <option value="" selected></option> <SCRIPT language="PerlScript"> use strict; use warnings; use feature 'say'; use XML::XPath; my $xp = XML::XPath->new(filename => 'State.xml'); my $querysshh = '/States/State'; $nodeset = $xp->find($querysshh); foreach $mynode ($nodeset->get_nodelist) { my $statenames = $myNode->getAttribute('Name'); print $statenames; $window->document->write("<option value='".$staten +ames."'>".$statenames."</option>"); } </SCRIPT> </SELECT> </body> </html>

      We use IE9 & IE11. So used the below code in the <script> tag

      HKEY_LOCAL_MACHINE\SOFTWARE\ActiveState\PerlScript\1.0 REG_DWORD: EnabledZones = 0x0010 (default)

      Still it did not work. Can you help me to understand the problem with my code better and how to make it work? Thanks!

        You still need to learn about HTTP and HTML and how they interact.

        The file you want to read here:

        my $xp = XML::XPath->new(filename => 'State.xml');

        will be read on the client, because your code runs on the client.

        But that file doesn't exist on the client, or even if it exists, you also need an absolute path to it that is readable from the client.

        Also, the version of Perl you have "on the client" above is Perl 5.6.1 (reaally ancient), and it does not support use feature 'say';.

        I feel your whole approach is misguided as you could implement all of the above without the reliance on PerlScript by simply producing the appropriate HTML server-side, using XML::XPath and Template::Toolkit for example.

        I suggest you re read the existing responses you have, explaining why your code doesn't do what you think it should. That's an ancient version of perl and there's a reason why nobody writes code like this (client side perlscript) anymore.

        Whichever way you take, you should get a newer Perl version. If that is not yours to do, at least approach the person who updated the Operating System without also updating relevant applications (that META tag you mentioned is about compatibility). Active Perl is at 5.24 meanwhile, the oldest listed on their website is 5.8 - I doubt they still support 5.6…

        The next point is, if you want to do this client side: not only will you need to have the "State.xml" file locally on each client in the appropriate place (which you'll have yet to find out), but you need XML::XPath and probably other modules installed on each client.

        So my recommendation is like the others' - go for server side. But have Perl updated anyway!