Re: trying to learn

Sandip Bhattacharya <[email protected]> Fri, 3 Sep 2004 12:43:32 +0530
Newsgroups gmane.user-groups.linux.delhi.devel
Organization Puroga Technologies Pvt. Ltd.
Message-ID <[email protected]>
On Friday 03 Sep 2004 12:00 pm, Ritesh Raj Sarraf wrote:
> print "Please enter multiple numbers separated by spaces on multiple
> lines.\n"; print "When finished, Press CTRL + D\n";
> @numbers = <STDIN>;

You get just one newline terminated line here. The stdin is line buffered by 
default.


my $sum = 0;
while (<>) {
    @_ = split /\s+/; #you can leave out LHS here but it is deprecated.
    foreach (@_) {
        $sum+=$_ if $_;
    }
}
print $sum."\n";

- Sandip

-- 
Sandip Bhattacharya    *    Puroga Technologies   *     sandip-/[email protected]
Work: http://www.puroga.com        *         Home: http://www.sandipb.net

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3

The Korean War must have been fun. MAKERS CONVENTION...