Need help with PerlScript (asp).

B

Brian

Hello all. I'm coding a site right now, but I don't know Perl or asp
(other than what I've learned in the last few days). I had someone
helping me write some ASP code, but it is in VBscript, unfortunately
my server only accepts PerlScript. I've converted as much of it as I
can, but it still doesn't work. It's a simple script, and I'm
wondering if someone can look it over and tell me what's wrong (most
likely a minor syntax thing). Thanks.

CONCEPT - I want the file ps2.asp to have a table that reads a text
file (ps2.txt) and uses the info in it as variables to display certain
files/info.
ps2.txt example -
grandtheftauto,used,19.95
truecrime,used,22.95

I need it to loop through each line, and display the information in
the table (as written in my code).


HERE IS THE CODE:

<%@language=PerlScript%>
<html>
<head>
<title>Ps2 Games - TEST PAGE</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<center><h1>TEST PAGE FOR gamedeals.ca</h1></center>
<p>
</p>
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set fso = $Server->CreateObject("Scripting->FileSystemObject")
set greeting = $fso->GetFile(server->MapPath("ps2.txt"))
set ts = $greeting->OpenAsTextStream(ForReading, -2)

my $varText

Do while not ts.AtEndOfStream
$varText = ts->ReadLine
$varText = split($varText,",")
%>
<table>
<tr>
<td><IMG SRC="<%=$varText(0)%>.jpg"></td>
<td><embed src="<%=$varText(0)%>.html"></embed></td>
<td><%=$varText(1)%><br>$<%=$varText(2)%></td>
</tr>
</table>
<%
loop

%>
<p>
</p>
Here is the bottom of the page...
</body>
</html>


Can anyone help me?
 
S

Sherm Pendley

Brian said:
Can anyone help me?

Simply put, you need to learn the Perl language. There's no "set" in Perl,
no "Const", statements end with a semicolon, and your "$"s appear to be
randomly placed.

Go to <http://learn.perl.org>, and start reading.

sherm--
 
R

Richard Morse

<%@language=PerlScript%>
<html>
<head>
<title>Ps2 Games - TEST PAGE</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<center><h1>TEST PAGE FOR gamedeals.ca</h1></center>
<p>
</p>
<%
Const ForReading = 1, ForWriting = 2, ForAppending = 8
set fso = $Server->CreateObject("Scripting->FileSystemObject")
set greeting = $fso->GetFile(server->MapPath("ps2.txt"))
set ts = $greeting->OpenAsTextStream(ForReading, -2)

my $varText

Do while not ts.AtEndOfStream
$varText = ts->ReadLine
$varText = split($varText,",")
%>
<table>
<tr>
<td><IMG SRC="<%=$varText(0)%>.jpg"></td>
<td><embed src="<%=$varText(0)%>.html"></embed></td>
<td><%=$varText(1)%><br>$<%=$varText(2)%></td>
</tr>
</table>
<%
loop

%>
<p>
</p>
Here is the bottom of the page...
</body>
</html>

I'm not sure how you think this looks at all like Perl. I haven't used
PerlScript, but I'm betting you need to start looking more at something
like:

<%@Language=PerlScript$>
<html>
<head>...</head>
<body>
<%
my $f = open(my $in, "<", $Server->MapPath("ps2.txt")) or die($!);
while(<$f>) {
my ($src, $line1, $line2) = split /,/;
%>
<table><tr>
<td><img src="<%=$src%>.jpg" alt="" /></td>
<td><embed src="<%=$src$>.html"></embed></td>
<td><%=$line1%><br><%=$line2%></td>
</tr></table>
<%
}
%>
more stuff
</body>
</html>

I'm not sure if the reading of files is done in this way -- I would
check out the documentation to be sure.

Be aware that case matters...

HTH,
Ricky
 
M

Matt Garrish

Brian said:
Hello all. I'm coding a site right now, but I don't know Perl or asp
(other than what I've learned in the last few days). I had someone
helping me write some ASP code, but it is in VBscript, unfortunately
my server only accepts PerlScript. I've converted as much of it as I
can, but it still doesn't work. It's a simple script, and I'm
wondering if someone can look it over and tell me what's wrong (most
likely a minor syntax thing). Thanks.

CONCEPT - I want the file ps2.asp to have a table that reads a text
file (ps2.txt) and uses the info in it as variables to display certain
files/info.
ps2.txt example -
grandtheftauto,used,19.95
truecrime,used,22.95

I need it to loop through each line, and display the information in
the table (as written in my code).


HERE IS THE CODE:

<snip>

I don't have a server handy, but the following untested code should do what
you want:

<%@Language=PerlScript%>
<%

use strict;
use warnings;
use vars qw/$Request $Response $Session/;

open(my $txtfile, '<', 'ps2.txt') or die "Could not open ps2.txt: $!";

my $varText;

while (my $line = <$txtfile>) {

my @values = split(/,/, $varText);

$varText .= <<TABLE;
<table>
<tr>
<td><IMG SRC="$values[0].jpg"></td>
<td><embed src="$values[0].html"></embed></td>
<td>$values[1]<br>$values[2]</td>
</tr>
</table>
TABLE

}

%>

<html>
<head>
<title>Ps2 Games - TEST PAGE</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<center><h1>TEST PAGE FOR gamedeals.ca</h1></center>

<%= $varText %>

<p>Here is the bottom of the page...</p>
</body>
</html>
 
M

Matt Garrish

Matt Garrish said:
<snip>

I don't have a server handy, but the following untested code should do what
you want:

<%@Language=PerlScript%>
<%

use strict;
use warnings;
use vars qw/$Request $Response $Session/;

open(my $txtfile, '<', 'ps2.txt') or die "Could not open ps2.txt: $!";

my $varText;

while (my $line = <$txtfile>) {

my @values = split(/,/, $varText);

Oops, that should be:

my @values = split(/,/, $line);

Matt
 
C

ChrisO

Brian said:
Hello all. I'm coding a site right now, but I don't know Perl or asp
(other than what I've learned in the last few days). I had someone
helping me write some ASP code, but it is in VBscript, unfortunately
my server only accepts PerlScript.

I consider this highly unlikely under IIS that PerlScript is supported
but VBScript is not. In most cases, it's entirely the other way around.
The only way this could possibly be true is if someone (1) installed
the PerlScript engine then (2) removed the VBScript engine (by deleting
or renaming the VBScript DLL).
I've converted as much of it as I
can, but it still doesn't work. It's a simple script, and I'm
wondering if someone can look it over and tell me what's wrong (most
likely a minor syntax thing). Thanks.

[Snipped code]

Do yourself a few favors here:

(1) Learn Perl first if you are going to use PerlScript. You don't even
need to know VBScript to code in PerlScript using IIS/ASP. Just learn
Perl first. Knowing Perl puts you 95% of the way to using PerlScript as
an ASP engine.

(2) DON'T attempt to convert VBScript code to PerlScript. VBScript is
about as stupid and idiotic a language as I've ever seen. The
PerlScript engine absolutely blows VBScript out of the water in every
way; there is no comparision between the two. So DON'T try to convert
VBScript to PerlScript.

For instance, in VBScript to open a text file (as you are trying to do),
yes, you have to use something as incrediblely stupid as a
"FileSystemObject" to do it. It takes a ridiculous number of objects,
methods and lines of code to read a text file in VBScript. In
PerlScript, you access text files as you would in normal Perl. And
handling a text file is just ONE example of this sort of thing. (I
honestly think in Redmond, people sit around and try to figure out the
most complicated way to make something work. It's like adding numbers
using logrythms and exponents. That company is so clueless when it
comes to raw technology... It took someone from OUTSIDE to architect
something like .NET.)

(3) Once you've got #1 and #2 down, then realize that in PerlScript,
yes, there are a FEW anomalies that you have to make allowances for in
order to make things work in ASP. Namely, the use of the ASP objects:
Session ($Session), Request ($Request), Response ($Response),
Application ($Application), and the two other objects I can't remember
off the top of my head right now. For instance, you can't "print" in
PerlScript, you have to $Response->Write(). But other than those few
things, PerlScript under ASP is 95% identical to Perl. So don't try to
do VBScript -> PerlScript conversions.

And just for the sake of others who are reading this (I wouldn't attempt
this if you are already having the difficulties you are having):
PerlScript ASP coupled with HTML::Template is an absolutely fabulous and
powerful environment to do Web development in. .NET-like capabilities
can be realized with PerlScript and HTML::Template.

-ceo
 

Ask a Question

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top