Re: [LIP] trying to learn
Raj Mathur <[email protected]>
| Newsgroups | gmane.user-groups.linux.india.programmers |
|---|---|
| Message-ID | <[email protected]> |
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 >>>>> "Ritesh" == Ritesh Raj Sarraf <[email protected]> writes: Ritesh> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ritesh> Hello everyone, While learning perl came across this Ritesh> problem, someone please help me understand it clear. Ritesh> This program is a simple exercise program from one of Ritesh> the perl books where multiple numbers separated by spaces Ritesh> and entered on separate lines (you'll understand it easily Ritesh> if you read the code below). The desired output is to have Ritesh> sum total of the number of each line and a grand total of Ritesh> all the lines. Ritesh> Below is my incomplete source code. I tried taking Ritesh> multiple lines into an array and then split them. In the Ritesh> for loop I want my new array name to be assigned at Ritesh> runtime like @line1, @line2 and so.. How do I do that ? Ritesh> Or is my procedure incorrect to get the desired output ?? Ritesh> Please help When I'm counting numbers I don't store them all in memory and then make a grand total -- I keep a running total and whenever I encounter a number I add it to the running total and then promptly forget it (the number, not the running total). That should fix the issue of having an array of lines. Use split to extract the numbers on each line. man perlre ; perldoc -f split Regards, - -- Raju - -- Raj Mathur [email protected] http://kandalaya.org/ GPG: 78D4 FC67 367F 40E2 0DD5 0FEF C968 D0EF CC68 D17F It is the mind that moves -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) Comment: Processed by Mailcrypt 3.5.8 <http://mailcrypt.sourceforge.net/> iD8DBQFBOBptyWjQ78xo0X8RAu3FAJwNdyRd2QQ+ANI4f6393ngEpbPQdwCaAyNn vzAyOIWrgBmxx22v1o5zlE0= =oRuh -----END PGP SIGNATURE----- ------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click