CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help Please!

 



zebu
New User

Feb 5, 2012, 8:46 PM

Post #1 of 4 (1226 views)
Help Please! Can't Post

I'm having trouble with this and could really use some help. I'd like to use an array and a loop to read <stdin> until a zero is entered. After that I'd like to output the numbers from the array and calc the sum.

This is what I've come up with so far...@array will only hold one variable at a time. Sorry I just can't get this thing to work.

#!/usr/bin/perl
print ("\nEnter an integer: ");
for ($n1 = <stdin>; $n1 > 0; @array = $n1)
{
print ("Enter an integer: ");
$n1 = <stdin>;
print (@array);
}


zebu
New User

Feb 5, 2012, 10:28 PM

Post #2 of 4 (1222 views)
Re: [zebu] Help Please! [In reply to] Can't Post

Bill,

First of all, thank you! I really appreciate your insight.

Secondly, is there a way to capture all of the inputs entered into an array but still give the user an option to "quit"?

Thanks again,

BG


BillKSmith
Veteran

Feb 6, 2012, 6:23 AM

Post #3 of 4 (1211 views)
Re: [zebu] Help Please! [In reply to] Can't Post

Sorry, I posted in the wrong thread and deleted that post.

See my reply in your Feb 6 thread.
Good Luck,
Bill


naven8
Novice

Feb 14, 2012, 3:22 PM

Post #4 of 4 (1164 views)
Re: [zebu] Help Please! [In reply to] Can't Post

Use do-while loop instead.
do{

print "Please enter the number";
$n1 = <stdin>;
chomp($n1);
print (@array,$n1);

}while ($n != 0);

print .....
add.....

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives