Hi i am a novice perl learner this simple perl program
$inputline= <STDIN>;
print "first input";
print( $inputline);
$inputline=<STDIN>;
print "second input";
print($inputline);
$sum= $inputline+$inputline;
print"sum 1stinput and 2ndinput";
print($sum);
output
perl count.pl
3
4
first input3
second input4
sum 1stinput and 2ndinput : 8
why is the output 8 instead of being 7?
Because you add
$inputlineto itself when it is4.If you want to sum the two inputs, you either have to do it with two variables, or do the addition before the variable changes. E.g.:
Or
You could do something simpler, such as:
Which is basically the equivalent of:
Use Ctrl-C or Ctrl-D to break out of the loop (Ctrl-Z in windows).