Need help with PerlScript (asp).

Discussion in 'Perl Misc' started by Brian, Jul 14, 2004.

  1. Brian

    Brian Guest

    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?
     
    Brian, Jul 14, 2004
    #1
    1. Advertising

  2. Brian wrote:

    > 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--

    --
    Cocoa programming in Perl: http://camelbones.sourceforge.net
    Hire me! My resume: http://www.dot-app.org
     
    Sherm Pendley, Jul 14, 2004
    #2
    1. Advertising

  3. In article <>,
    (Brian) wrote:

    > <%@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
     
    Richard Morse, Jul 14, 2004
    #3
  4. Brian

    Matt Garrish Guest

    "Brian" <> wrote in message
    news:...
    > 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>
     
    Matt Garrish, Jul 14, 2004
    #4
  5. Brian

    Matt Garrish Guest

    "Matt Garrish" <> wrote in message
    news:sihJc.18987$...
    >
    > "Brian" <> wrote in message
    > news:...
    > > 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);
    >


    Oops, that should be:

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

    Matt
     
    Matt Garrish, Jul 14, 2004
    #5
  6. Brian

    ChrisO Guest

    Brian wrote:

    > 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
     
    ChrisO, Jul 17, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KaXo

    Using PerlScript In ASP

    KaXo, Mar 1, 2004, in forum: Perl
    Replies:
    2
    Views:
    593
  2. tuspa
    Replies:
    0
    Views:
    653
    tuspa
    Jul 20, 2007
  3. tuspa
    Replies:
    0
    Views:
    2,656
    tuspa
    Jul 20, 2007
  4. Replies:
    3
    Views:
    180
    Bob Barrows [MVP]
    Jan 25, 2006
  5. LinnAxis
    Replies:
    9
    Views:
    151
    Tad McClellan
    Jan 27, 2005
Loading...

Share This Page