in reply to Re^2: How to add values of hash by reading from different text files
in thread How to add values of hash by reading from different text files

The previous post was me. I forgot to sign in when i posted that. Sorry.
  • Comment on Re^3: How to add values of hash by reading from different text files

Replies are listed 'Best First'.
Re^4: How to add values of hash by reading from different text files
by CountZero (Bishop) on Apr 27, 2009 at 09:56 UTC
    Well, the use of lexical variables or --in other words-- the my operator is something you should look into very quickly. It makes for very clean programming, allowing you to use variables in sub-routines and loops without having them effect anything outside of the sub-routine or loop. Read the Private Variables via my() chapter in perldoc perlsub if you want to know more.

    That being said, you can drop all the my keywords in my program and if you also delete the use strict; it will still run fine, but you really, really should look into the use of my (and use strict;). It wil save you a lot of time and effort over and over again and will guard against stupid and silly mistakes.

    The way my program is written, it will always only read one line of the file in memory at any time, so your files can actually have millions of lines and it will still work.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James