The problem is ,in the following .
$nbArguments = $#ARGV + 1;
print "number of arguments: $nbArgumentsn";
exit(1) unless $nbArguments == 5;
Here you are checking the number of arguments is five.
So it will fail if you are giving input in the following format.
1 + 2 3
So that time you need to check the number of arguments is equal to four.
If you want to give input like,
1 + 2 + 3
then that time you need to check the number of arguments is equal to five.And you need to change the following part of code also.
your code,
$a = $ARGV[0];
$operation = $ARGV[1];
$b = $ARGV[2];
$c = $ARGV[3]
Change into,
$val1 = $ARGV[0];
$operation1 = $ARGV[1];
$val2 = $ARGV[2];
$operation2 = $ARGV[3]
$val3=$ARGV[4]
These changes are needed only in the case of if you are giving input in the format 1 + 2 + 3 .
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|