codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  sum of columns  pangpang at 01:06 on Tuesday, March 03, 2009
 

Hi,

I have a file with four rows, 2 columns
1 2 1 2
3 4 5 6
7 6 4 6
1 1 1 1

Output the sum of columns

My code is:
for (i=0; i<4; i++){
while<INPUT>{
$line=$_;
chop($line);
@bps=split(/\t/,$line);
sum[$i] += $bps[$i];
}
}

Anybody can tell me
What's wrong with this code? :(

  Re: sum of columns  hermanningjaldsson at 07:56 on Tuesday, March 03, 2009
 

first of all its not commented.

secondly it mixes multiple actions, like, reading the information into array and processing the information.

thirdly there's no tabbing, tabbing is very important to maintain readability.

'I have a file with four rows, 2 columns'
this looks like four rows and four columns to me.



the input filehandle isn't defined before it is applied.



  Re: sum of columns  pangpang at 15:36 on Tuesday, March 03, 2009
 

Thank you very much for your words. You are absolutely right.
I realized that my code is poorly maintained.
I will work harder.
Thank you again.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
//








Recent Forum Threads
•  Re: Passing Password using $ssh->cmd
•  Re: sum of columns
•  pop up Click-able Calendar need to output to 3 text fields
•  need HELP importing a data file....
•  Read Huge File into Hash
•  Client Server Communication
•  Linking two separate iframes from two different wepages
•  Linking two separate iframes from two separate webpages
•  Re: number of regex match


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2009