in reply to Needed Performance improvement in reading and fetching from a file

I can't honestly see anything wrong with doing that split nor any reason that you have a performance issue with only 20k records.

However...

  1. chomp is a superfluous operation - why strip from the end of the line when you are only reading the second field?
  2. I know that you say this is a code fragment. One thing to consider if it were not a fragment is that you first populate an array then run through and print from it. That push() could have been print "$data[1]\n"; rather than running through two loops.
  3. Are you absolutely sure that your performance issues are coming from here and not elsewhere in your code?

Hope this helps.

  • Comment on Re: Needed Performance improvement in reading and fetching from a file
  • Download Code

Replies are listed 'Best First'.
Re^2: Needed Performance improvement in reading and fetching from a file
by CountZero (Bishop) on Oct 08, 2008 at 05:46 UTC
    you first populate an array then run through and print from it

    Look again: the OP is indeed --unnecessarily-- populating an array, but he is not looping through it. He indexes into the array in the push.

    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

      Sorry - obviously didn't make myself clear. I meant looping through the @refnos array (with foreach) to print, not looping through the @data array; in the example, the @refnos array is superfluous although it is probably doing more in the whole application - or at least I hope it is.

      I wasn't actually aware - or had forgotten - that split could be limited like your CountZero's example. Every day I learn something (or am reminded of it) is a day not wasted. Or something.