Irishboy24 has asked for the wisdom of the Perl Monks concerning the following question:
#Here is the Input Enter a number (999) to quit 1 2 3 4 999
#Actual Script #!/usr/bin/perl use strict; use warnings; sub add_nums { # body... # Add numbers entered at STDIN print "Enter a number (999) to quit\n"; chomp(my $n = <>); my $sum = 0; while ($n != 999) { $sum += $n; chomp($n = <>); } print "The Sum is $sum\n"; } add_nums;
The script basically adds all the numbers entered at STDIN until it encounters 999. Two Questions:#Output The Sum is 10
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: confusion with Chomp
by stevieb (Canon) on Apr 08, 2016 at 00:13 UTC | |
by Irishboy24 (Sexton) on Apr 08, 2016 at 01:15 UTC | |
|
Re: confusion with Chomp
by Marshall (Canon) on Apr 08, 2016 at 00:08 UTC | |
by BillKSmith (Monsignor) on Apr 08, 2016 at 18:49 UTC | |
by Marshall (Canon) on Apr 08, 2016 at 19:19 UTC |