I have a reasonably simple problem I need to solve.
I have built a calculator which basically stores each function to a file. For example when I press the button 1 it adds "1" to the file, then i press + so it adds "+" to the file (therefore the file currently has "1+" stored in it.
The idea is to then open that file under a variable i.e. @calculate and work out the sum. So imagine I had stored in the file 1+1. I would like to do the following:
$finalSUM = @calculate;
I assumed that I would get this result
$finalSUM = 1+1;
therefore $finalSUM = 2
However I am getting the result of 1 for every sum completed. I assume this is because of perl being unable to to use @calculate (1+1) and calculate it in this way... Please help
Here is part of my code...
#! /usr/bin/perl
use strict;
use CGI ':standard';
my ($calculate);
open (LOG, "</../../../../../../../../../calculations.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
my @calculations = <LOG>;
close (LOG) || Error ('close', 'file');
$calculate = (@calculations);
open (LOG, ">/../../../../../../../../../calculations.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "$calculate";
close (LOG);
#####################
## Print statement ##
#####################
print "Content-type: text/html\n\n";
print <<"HTML code";
<HTML><HEAD>
<TITLE>HTML Editor/Viewer</TITLE>
<meta http-equiv="Refresh" content="1; url=http://www.ChrisMassey.co.uk/Perl/Scripts/Calculator/Calculations.txt">
</HEAD><BODY>
<p><font size="2" face="Arial"><a href="calculations.txt">Complete</a></font></p>
</BODY></HTML>
HTML code
print "";
###########
## Error ##
###########
sub Error {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>The server can't $_[0] the $_[1]: $! \n</font>";
exit;
}
Imagine stored in the file calculations.txt is 1+1+1
The result i get is "1" when it should be "3
I have built a calculator which basically stores each function to a file. For example when I press the button 1 it adds "1" to the file, then i press + so it adds "+" to the file (therefore the file currently has "1+" stored in it.
The idea is to then open that file under a variable i.e. @calculate and work out the sum. So imagine I had stored in the file 1+1. I would like to do the following:
$finalSUM = @calculate;
I assumed that I would get this result
$finalSUM = 1+1;
therefore $finalSUM = 2
However I am getting the result of 1 for every sum completed. I assume this is because of perl being unable to to use @calculate (1+1) and calculate it in this way... Please help
Here is part of my code...
#! /usr/bin/perl
use strict;
use CGI ':standard';
my ($calculate);
open (LOG, "</../../../../../../../../../calculations.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
my @calculations = <LOG>;
close (LOG) || Error ('close', 'file');
$calculate = (@calculations);
open (LOG, ">/../../../../../../../../../calculations.txt") || Error('open', 'file');
flock (LOG, 2) || Error('lock', 'file');
print LOG "$calculate";
close (LOG);
#####################
## Print statement ##
#####################
print "Content-type: text/html\n\n";
print <<"HTML code";
<HTML><HEAD>
<TITLE>HTML Editor/Viewer</TITLE>
<meta http-equiv="Refresh" content="1; url=http://www.ChrisMassey.co.uk/Perl/Scripts/Calculator/Calculations.txt">
</HEAD><BODY>
<p><font size="2" face="Arial"><a href="calculations.txt">Complete</a></font></p>
</BODY></HTML>
HTML code
print "";
###########
## Error ##
###########
sub Error {
print "Content-type: text/html\n\n";
print "<font face=arial size=2>The server can't $_[0] the $_[1]: $! \n</font>";
exit;
}
Imagine stored in the file calculations.txt is 1+1+1
The result i get is "1" when it should be "3