Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:33:30+00:00 2026-06-13T15:33:30+00:00

Hi i am a novice perl learner this simple perl program $inputline= <STDIN>; print

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:33:31+00:00Added an answer on June 13, 2026 at 3:33 pm

    Because you add $inputline to itself when it is 4.

    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.:

    my $input1 = <>;
    my $input2 = <>;
    my $sum = $input1 + $input2;
    print "Sum: $sum";
    

    Or

    my $input = <>;
    my $sum = $input;
    $input = <>;
    $sum += $input;
    print "Sum: $sum";
    

    You could do something simpler, such as:

    perl -nlwe '$sum += $_; print "Sum: $sum";'
    

    Which is basically the equivalent of:

    use strict;
    use warnings; # always use these
    
    my $sum;
    while (<>) {  # your input
        $sum += $_;
        print "Sum: $sum\n";
    }
    

    Use Ctrl-C or Ctrl-D to break out of the loop (Ctrl-Z in windows).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a perl script that prepares files for input to a binary program
here's my first ever perl program: I want to make sure that if I'm
This may be very novice of me, but I am a novice at Perl
Php novice. 1.Is there anything wrong with this PHP & MySQL code? include_once db_login.php
I am a novice to spring dm so pardon my simple question. I downloaded
As I'm a novice, I started learning python by writing simple programs using python
I'm a novice in XSLT and I'm struggling a lot with this issue: I
Am fairly new to using MySQL and a total novice at Perl but am
please help! I'm really going nuts with this problem! I have a CGI perl
Let's say I have the following simple script: print ID : ; $ID =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.