
wild.katana
New User
Jan 14, 2008, 2:18 PM
Post #1 of 2
(111 views)
|
|
Help writing a script using array and STDIN
|
Can't Post
|
|
Hello, this is my first time posting here. I am a student and have a PERL college class. I am familiar with a few other programming languages but not PERL (yet!). I have a question in regards to using <STDINPUT> to write number elements to an array, until a blank line is entered. I then want to find out how many numbers are less than the last number entered (the last index of the array). My code I have so far is:
@numbers = <STDIN>; $lastNum = $numbers[-1]; $lessThan = 0; $i = 0; while ($i < $#numbers) { if ($lastNum > $numbers[$i]) { $lessThan += 1; } $i ++; } print "$lessThan numbers were less than $lastNum."; I'm not sure what the problem is... The program is supposed to read numbers as many times as the user puts a new number until the user inputs a blank line, then perform the operation on the array. Any ideas? Need clarification? Sorry I am a newbie at this. Thanks in advance!
|