Solved

beginner question

Posted on 1998-09-24
2
147 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 10 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
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…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…

920 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

12 Experts available now in Live!

Get 1:1 Help Now