?
Solved

beginner question

Posted on 1998-09-24
2
Medium Priority
?
157 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
ID: 1828782
Edited text of question
0
 
LVL 5

Accepted Solution

by:
b2pi earned 40 total points
ID: 1828783
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
Measuring Server's processing rate with a simple powershell command. The differences in processing rate also was recorded in different use-cases, when a server in free and busy states.
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Suggested Courses
Course of the Month17 days, 8 hours left to enroll

829 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