?
Solved

need some help getting this simple perl program to run

Posted on 2009-05-12
5
Medium Priority
?
975 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
[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
  • 2
5 Comments
 
LVL 84

Assisted Solution

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

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
Six Sigma Control Plans
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