Solved

beginner question

Posted on 1998-09-24
2
146 Views
Last Modified: 2013-12-25
I try to use a counter in my HTML page, but it doesn't
work...

I use this script PERL :
--[BEGIN - counter.pl]---------------------------
#!/usr/local/bin/perl -s


$filename="./counter.txt";


if (!open(COUNTER, "$filename"))
  {
    print "couldn't open for read\n;"
  }

else
  {
    $count=<COUNTER>;
    close (COUNTER);
   
    if ($count =~ /\n$/)
      {
      chop($count);
      }
  }

$count++;



if(!open(COUNTER, ">$filename"))
  {
    print "couldn't open for print\n";
  }
else
  {
    print COUNTER "$count";
    close (COUNTER);
  }

print "$count";

--[END - counter.pl]---------------------------
and I use a JavaScript function in my HTML file :

counter(<!C-#exec cgi="/cgi-bin/counter.pl")

this function work fine if I write
counter(23) for exemple. My counter is well display 23.
But when I try with the CGI bellow : Nothing appears !!!

Note, I use CERN HTTP Server on Solaris
0
Comment
Question by:baresse
2 Comments
 
LVL 1

Author Comment

by:baresse
Comment Utility
Edited text of question
0
 
LVL 5

Accepted Solution

by:
b2pi earned 10 total points
Comment Utility
If I understand you properly, this works fine from the command line,
yet seems to fail when called via the java script?

See that line

$filename="./counter.txt";


??  Well, what is '.' when you're running from the server?  Do you
have write rights? Can you create a file there?  Does the file already
exist? [Hint: Specify the absolute path of the file].

By the way, when you're printing from the script, where does the
output go? [More hints: it goes to never never land].

Try this

open(COUNTER, $filename)
    || die "Content-type: text/html\nUnable to open file: $!";


Also, try running

perldoc chomp

to see a better way of getting around that if statement in the middle
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo‚Ķ
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now