[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

need some help getting this simple perl program to run

Posted on 2009-05-12
5
Medium Priority
?
978 Views
Last Modified: 2012-05-06
print "Rey Calculator";
print "\n";
print "Please Enter the first Number";
chomp($a = <STDIN>);
print "\n";
print "Please Enter the second Number\n";
chomp ($b = <STDIN>);
print "\n";
print "Please Enter the Operator"
chomp ($operation = <STDIN>);
print "\n";
#The following if statement assigns the command line arguments to a variable ($operation)
if ($operation eq +) {
$result = $a + $b;
}elsif ($operation eq -) {
$result = $a - $b;
}elsif ($operation eq /) {
$result = $a / $b;
}elsif ($operation eq x) {
$result = $a * $b;
}
print $a $operation $b = $result\n;


C:\>perl cal.pl
syntax error at cal.pl line 10, near "chomp"
Unrecognized character \x93 in column 19 at cal.pl line 13
0
Comment
Question by:1030071002
  • 2
  • 2
5 Comments
 
LVL 85

Assisted Solution

by:ozo
ozo earned 160 total points
ID: 24371589
missing ; between
print "Please Enter the Operator"  
and
chomp ($operation = <STDIN>);
0
 
LVL 85

Assisted Solution

by:ozo
ozo earned 160 total points
ID: 24371594
And what is the character between the eq and the +
if ($operation eq +) {
0
 
LVL 39

Assisted Solution

by:Adam314
Adam314 earned 80 total points
ID: 24371643
This appears to be homework... is it?  If so, experts can help point you in the right direction, but can not do the work for you.
0
 
LVL 5

Accepted Solution

by:
vikaskhoria earned 260 total points
ID: 24371658
There are two problems in the above script:
* First is a missing semicolon at the end of line no. 9 (print "Please Enter the Operator")
* Second is you need to put all the operators in the if statements in quotes. like '+'
So your line no. 13 now becomes:
if ($operation eq '+') {

This is because you are comparing $operation as a text value.
I have debugged the code tried running it and is working fine now.
Find the corrected script below:

print "Rey Calculator";
print "\n";
print "Please Enter the first Number";
chomp($a = <STDIN>);
print "\n";
print "Please Enter the second Number\n";
chomp ($b = <STDIN>);
print "\n";
print "Please Enter the Operator";
chomp ($operation = <STDIN>);
print "\n";
#The following if statement assigns the command line arguments to a variable ($operation)
if ($operation eq '+') {
$result = $a + $b;
}elsif ($operation eq '-') {
$result = $a - $b;
}elsif ($operation eq '/') {
$result = $a / $b;
}elsif ($operation eq x'') {
$result = $a * $b;
}
print $a $operation $b = $result\n;

Open in new window

0
 
LVL 5

Assisted Solution

by:vikaskhoria
vikaskhoria earned 260 total points
ID: 24371675
One small in copy paste above.On line 20 by mistake have type x'', it should be 'x'
0

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.

Question has a verified solution.

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

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Six Sigma Control Plans
Suggested Courses

810 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