in reply to Re^2: Reading individual bits
in thread Reading individual bits

Whilst I'm looking, this bit of code is very strange--and slow.

@$ItemListRef = (@$ItemListRef,$NumOut, "\t");

You

  1. pass in a reference to an array,
  2. dereference that array to produce a list,
  3. tack the latest value and a tab onto the end of the list
  4. and then assign that back to the original array.

This action is the same as doing:

push @$ItemListRef, $NumOut, "\t";

Accept that it uses gob-loads (tech. term) of memory in building lots of intermediate lists in the process. No wonder your subroutine is slow.

Also, why are you interspersing your values with tabs?

If the intention is to print them as tab-delimited list to a file or the screen. Just build the array without the inspersed tabs and then use join to add teh tabs when you print.

print join "\t", @ItemList;

Not only will you save half the memory of your list, by not allocating it you'll save a bit more time.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail
"Memory, processor, disk in that order on the hardware side. Algorithm, algoritm, algorithm on the code side." - tachyon

Replies are listed 'Best First'.
Re^4: Reading individual bits
by Anonymous Monk on Jul 30, 2004 at 13:41 UTC
    you can also use perl's $, variable to set the "output field seperator" to put tabs in between a elements passed to print in a list.

    i.e.

    rather than:
    print join "\t", @ItemList;

    you could do:
    local $, = "\t"; print @ItemList;

    doing a quick profile of these showed only a 3-4% increase in speed so code readability might outweigh performance in this case