CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
shtml problem

 



kade
Deleted

Jun 26, 2000, 2:58 AM

Post #1 of 5 (722 views)
shtml problem Can't Post

Hi friends!
I asked once about the html tag to insert a perl file (for a counter),and already got answer but some problem remains;
here is my code(hit.pl);
open (HIT,"hit.txt");
$count=<HIT>;
close(HIT);
$count++;
open(HIT,"hit.txt");
print HIT"$count";
close(HIT);
@hitarray=split(//,$count);
$max=@hitarray;
for($i=0;$i<$max;$i++){
print"<imgsrc=http://www.mombuddy.com$hitarray[$i]\.gif\"border=owidth=15height=20>";
}
####
here is the html tag;
<p align="center"><!--#exec cgi="http://www.mombuddy.com/hit.pl"--></td>

:: this doesn't work, no counter shown on my homepage;
then I tried saving the page as index.shtml and uploaded it.The server notified as an error!
What's to do now?
Thanks




mwaf
Deleted

Jun 26, 2000, 4:30 AM

Post #2 of 5 (722 views)
Re: shtml problem [In reply to] Can't Post

Shouldn't

print"<imgsrc=http://www.mombuddy.com$hitarray[$i]\.gif\"border=owidth=15height=20>";

be:

print"<img src=http://www.mombuddy.com/$hitarray[$i].gif border=0 width=15 height=20>";

also you don't have anything in the beginning
#!/usr/bin/perl and you don't have print "Content-type:text/html\n\n"; anywhere either (though maybe you didn't post the whole script)


if this doesn't make any difference try first if a text counter works (replace everything after close(HIT); with:

print "$count";

[This message has been edited by mwaf (edited 06-26-2000).]


DrZed
User

Jun 26, 2000, 5:57 PM

Post #3 of 5 (722 views)
Re: shtml problem [In reply to] Can't Post

 <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">quote:</font><HR>open (HIT,"hit.txt");
$count=<HIT>;
close(HIT);
$count++;
open(HIT,"hit.txt");
print HIT"$count";
close(HIT);
@hitarray=split(//,$count);
$max=@hitarray;
for($i=0;$i<$max;$i++){
print"<imgsrc=http://www.mombuddy.com$hitarray[$i]\.gif\"border=owidth=15height=20>";
<HR></BLOCKQUOTE>

The problem was probably the missing slash, but here are a few notes.

Don't do an 'open' without checking to see if it happens or not.

If you don't lock the file, your likly to get your counter reset if two people hit the counter at the exact same time.

You don't need to open the file twice.

You have a quote at the end of the src, but not at the beginning.

There are two lines that I'm not sure about (mostly because I'm new to Perl, they are not necessarily wrong).

@hitarray=split(//,$count);
$max=@hitarray;

While this may very well work, you could use substr and length.

Here's an alternate version of your code:

Please note that &#0124; &#0124; is supposed to be two |'s WITHOUT any space in between.

open (HIT,"+<hit.txt") &#0124; &#0124; die $!;
flock(HIT,2);
$count=<HIT>;
++$count;
seek (HIT,0,0);
print HIT $count;
close(HIT);
for($i=0;$i<length($count);$i++)
{
print '<img src="http://www.mombuddy.com/',substr($count,$i,1),qq{.gif" border=0 width=15 height=20>};
}

Some final notes:

If you have trouble, check what HTML it's sending. If it returns something, it might give you a clue to the error.

I prefer using qq{} instead of "" simply to avoid having to backslash quote marks.

You didn't need to backslash the . before gif. If it were a regex, you would need to.

I may be wrong about some of this. Hopefully, some Perl guru can proof my comments.

Dr. Zed


kade
Deleted

Jun 26, 2000, 6:41 PM

Post #4 of 5 (722 views)
Re: shtml problem [In reply to] Can't Post

 
Hi friends!
Now I've corrected all the error you suggested;
Here's my corrected scripts;(hit.pl)
$count++;
open(HIT,"hit.txt");
print HIT"$count";
close(HIT);
@hitarray=split(//,$count);
$max=@hitarray;
for($i=0;$i<$max;$i++){
print"<img src=http://www.mombuddy.com/$hitarray[$i].gif border=o width=15 height=20>";
}
####
I built it with the "Perl Builder" then view the output, it works.
but now the problem is at the html tag, I think.
this is the tag;
<p align="center"><!--#exec cgi="http://www.mombuddy.com/hit.pl"--></p>
After insertion, it returns nothing on the homepage.
Any suggestion?
Thanks




mwaf
Deleted

Jun 26, 2000, 9:47 PM

Post #5 of 5 (722 views)
Re: shtml problem [In reply to] Can't Post

I doubt that any perl script will run without being placed in a cgi-bin or bin (depending in the server) folder. The server must support SSI, also rename the html file to .shtml (if this works you can always try if it'll do without the 's')

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives