?
Solved

beginner question

Posted on 1998-09-24
2
Medium Priority
?
153 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Suggested Courses

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