Welcome to Dream.In.Code
Become an Expert!

Join 149,576 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,722 people online right now. Registration is fast and FREE... Join Now!




Perl Var to JScript

 
Closed TopicStart new topic

Perl Var to JScript

nemo1966
12 Oct, 2007 - 12:50 AM
Post #1

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 3


My Contributions
Hi,
I come to this forum in the hope you actually have a few Perl experts amongst your ranks. I have tried 4 forums to date with no resolution to my seemingly simple problem.

I am a programmer by profession but have never delved into the World of Perl.

Problem:
I need to pass a variable from Perl to java script: In this case its an IP address.

I cannot change the page to something easier to use like php etc hence being forced to use Perl and Jscript.

Below is what experts have got up to now, however it does not work:

Perl code:
CODE
#!/usr/bin/perl -wT
use strict;
use CGI;
print CGI::header('text/text');
print qq/var IP="$ENV{'REMOTE_ADDR'}"/;


html jscript code:
CODE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Javascript Test</title>
    <script LANGUAGE="JavaScript" SRC="/cgi-bin/ip"></SCRIPT>
</head>
<body>
    <script LANGUAGE="JavaScript">alert(IP);</SCRIPT>
</body>
</html>


In the perl code someone said that the quotes need escaping like this:
CODE
print qq/var IP=\"$ENV{'REMOTE_ADDR'}\"/;


However when running the page I still get Var IP not defined as a jscript error.

Test urls are here
CODE
http://www.rimmelsoft.co.uk/iptest.htm


Perl is here
CODE
http://www.rimmelsoft.co.uk/cgi-bin/ip


Any help would gratefully be received

regards
nemo1966

PS the Perl cgi-bin is tested and working

PPS I know this can be done see:
CODE
http://www.searchnc.com/cgi-bin/myip.pl

This works in exactly the way I desribe, however I cannot find anyone with the knowledge to mimic its functionality.

This post has been edited by nemo1966: 12 Oct, 2007 - 12:52 AM
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Perl Var To JScript
12 Oct, 2007 - 09:52 AM
Post #2

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 238



Thanked: 6 times
Dream Kudos: 50
My Contributions
You're passing a perl script as the source file to your javascript tag?

<script LANGUAGE="JavaScript" SRC="/cgi-bin/ip"></SCRIPT>

this returns a 500 error:

http://www.rimmelsoft.co.uk/cgi-bin/ip

this wants to download the perl script:

http://www.rimmelsoft.co.uk/cgi-bin/ip.pl

which results in a one line file:

var IP="66.53.214.8"

there is no perl code. There is no perl variable. This makes no sense.



User is offlineProfile CardPM
+Quote Post

mocker
RE: Perl Var To JScript
14 Oct, 2007 - 09:48 AM
Post #3

D.I.C Regular
Group Icon

Joined: 14 Oct, 2007
Posts: 289



Thanked: 17 times
Dream Kudos: 25
My Contributions
I made a quick example of what you done at http://thegupstudio.com/exampleip.html , which calls http://thegupstudio.com/cgi-bin/showip.pl

The perl code is very simple:

CODE

#!/usr/bin/perl

#show the users IP in javascript
print "Content-type: text/html\r\n\r\n";
print "var yourip=\"".$ENV{'REMOTE_ADDR'}."\";";


The html code is very simple as well, the javascript lines just look like:

CODE

<script language="javascript" src="/cgi-bin/showip.pl"></script>
<script language="javascript">
function showIP(){
alert("Your IP is: "+yourip);
}
</script>


simple little example, but you can have the perl create any javascript code you need. Paired with dynamically fetching the content of said perl script, you have a fun little thing called AJAX basically. Make sure your perl cgi script is executable, or you could do the same thing with php.
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Perl Var To JScript
14 Oct, 2007 - 09:55 AM
Post #4

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Thanks for helping out mocker and welcome to dream.in.code!
User is offlineProfile CardPM
+Quote Post

nemo1966
RE: Perl Var To JScript
15 Oct, 2007 - 03:33 AM
Post #5

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 3


My Contributions
OMG you are a saint!!

First person in 5 boards to be able to crack it.

thank you Sir!

This post has been edited by nemo1966: 15 Oct, 2007 - 03:34 AM
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Perl Var To JScript
15 Oct, 2007 - 09:47 AM
Post #6

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 238



Thanked: 6 times
Dream Kudos: 50
My Contributions
All that does is print what would be the contents of a static javascript soure code file. That is not the same as the question you asked which is probably why nobody was able to supply a correct answer. Kudos to mocker for figuring out a solution to a poorly worded queston.
User is offlineProfile CardPM
+Quote Post

nemo1966
RE: Perl Var To JScript
17 Oct, 2007 - 05:51 AM
Post #7

New D.I.C Head
*

Joined: 12 Oct, 2007
Posts: 3


My Contributions
Untrue if you look at the searchnc.com example I gave it does EXACTLY the same tongue.gif icon_up.gif

Poorly worded? LOL you mean you just didn't understand it? It seems someone did though. Stop trying to offset your lack of intelligence by blaming everyone else for your short-comings.

This post has been edited by nemo1966: 17 Oct, 2007 - 05:56 AM
User is offlineProfile CardPM
+Quote Post

skyhawk133
RE: Perl Var To JScript
17 Oct, 2007 - 06:05 AM
Post #8

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
Whoa Whoa Whoa nemo. Don't come to my forum asking for help and then verbally attack someone that tried to help you. Poorly worded or not, you got the help you needed.

Thread closed.
User is offlineProfile CardPM
+Quote Post

Closed TopicStart new topic
Time is now: 1/7/09 10:34PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month