Solved

Perl/win95/website 1.1

Posted on 1997-08-02
8
191 Views
Last Modified: 2010-05-18
I have a simple counter from a book which can't read the data in the counter.txt. Is there a DOS/WIN95 version of chmod or does the script(see below) need a modification. It would also be nice if I could run perl scripts without the Dos window coming up everytime-Any help gratefully appreciated
Mick
#!/usr/local/perl/bin/perl


print "Content-type: text/html", "\n\n";

$count_file = "/usr/local/perl/bin/httpd_1.4.2/count.txt";

if (open (FILE, ">" . $count_file)) {
    $no_accesses = <FILE>;
    close (FILE);

    if (open (FILE, ">" . $count_file)) {
        $no_accesses++;

        print FILE $no_accesses;
        close (FILE);

        print $no_accesses;
    } else {
        print "[ Can't write to data file! Counter not incremented! ]", "\n";
    }

} else {
    print "[ Sorry! Can't read the counter data file ]", "\n";
}

exit (0);    







0
Comment
Question by:mick_hutton
  • 5
  • 3
8 Comments
 
LVL 2

Accepted Solution

by:
n3mtr earned 20 total points
ID: 1205166
The first time you open the file it should be for reading, not writing. Change it to:
if (open (FILE, $count_file)) {
                $no_accesses = <FILE>;
                close (FILE);
Notice no > before the file name.
Comment back if you are still having problems.
0
 

Author Comment

by:mick_hutton
ID: 1205167
Thankyou for a prompt answer i will go and try it and get back if I have any problems
0
 

Author Comment

by:mick_hutton
ID: 1205168
I'm afriaid it still won't work Goes straight to [Sorry can't read the data file] as before, I think I got the path right but how do you intialise count.txt in win95 and set the count.txt for access (like chmod 777 in perl)? maybe this is the problem
Thanks Mick
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 2

Expert Comment

by:n3mtr
ID: 1205169
All files in windows95 are mod 777(world read,write, and execute).
I think I found it, windows95 does not allow two periods in a filename.  Its prabably hanging up on httpd_1.4.2 try changing the path to only one period(maybe httpd_1_4.2).
Also check to make sure the file exists and has a number in it followed by a newline.

0
 

Author Comment

by:mick_hutton
ID: 1205170
Thanks again but no joy. Do you have to do anything to the file in win95 to mod 777 or is it already set to that?
I,m new to this so let me explain what I've done so far.
Website 1.1 set as localhost in win95 all other simple scripts work so far this is the first one to open a file.
I have now set mapping in website setup /counter/(url) mapped to the full dir path to my count.txt. The script now looks like this and comes up with syntax OK but the same result [can't read data from data file]
#!/usr/local/perl/bin/perl




print "Content-type: text/html", "\n\n";

$count_file = "/counter/count.txt";


if (open (FILE, $count_file)) {
     $no_accesses = <FILE>;
     close (FILE);

    if (open (FILE, $count_file)) {
        $no_accesses++;

        print FILE $no_accesses;
        close (FILE);

        print $no_accesses;
    } else {
        print "[ Can't write to data file! Counter not incremented! ]", "\n";
    }

} else {
    print "[ Sorry! Can't read the counter data file ]", "\n";
}

exit (0);    

I have also ammended the count.txt to [0, "\n"; ] no boxed brackets.
I think this is all thankyou again in advance
Mick
0
 

Author Comment

by:mick_hutton
ID: 1205171
Please ignore above comment I now have counter working I had to put in dir path with \\ double backslash and not url map I set up in website. Now problem is it counts 2 everytime by adding 2 to the count.txt and also the content: text/html printed with the visit number I got round this by print "\n\n"; instead as below

#!/usr/local/perl/bin/perl

print  "\n\n";

$count_file = "d:\\website\\htdocs\\counter\\count.txt";

if (open (FILE, $count_file)) {
     $no_accesses = <FILE>;
     close (FILE);

    if (open (FILE, ">" . $count_file)) {
        $no_accesses++;

        print FILE $no_accesses;
        close (FILE);

        print $no_accesses;
    } else {
        print "[ Can't write to data file! Counter not incremented! ]", "\n";
    }

} else {
    print "[ Sorry! Can't read the counter data file ]", "\n";
}

exit (0);    
Hopefully we are nearly there thanks for your help

0
 
LVL 2

Expert Comment

by:n3mtr
ID: 1205172
I don't see anything wrong with the script.  Could it be that you are calling it twice in your webpage?

0
 

Author Comment

by:mick_hutton
ID: 1205173
Thats what I thought but I have tried various permutations and can't see why. Thanks anyway I will keep trying
Mick
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Syslog text file into database or into .CSV 19 142
work on ods spreadsheet with perl in ubuntu 4 76
Insert Text into odbc.ini file 15 66
Log File Creation with Header and Footer 17 96
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

777 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