• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 160
  • Last Modified:

beginner question

I try to use a counter in my HTML page, but it doesn't

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


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

    close (COUNTER);
    if ($count =~ /\n$/)


if(!open(COUNTER, ">$filename"))
    print "couldn't open for print\n";
    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
1 Solution
baresseAuthor Commented:
Edited text of question
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


??  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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now