in reply to Memory consumption

This statement is duplicating the entire hash:

my %hash = get_hash();

Instead of:

get_hash { my %hash; ## populate %hash; ... return %hash; } ... my %hash = get_hash(); ... if( defined( $hash{ $data[0] } ) ) {

Use:

get_hash { my %hash; ## populate %hash; ... return \%hash; } ... my $hashRef = get_hash(); ... if( defined( $hashRef->{ $data[0] } ) ) { ## Note the arrow .......^^

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."

Replies are listed 'Best First'.
Re^2: Memory consumption
by pachkov (Novice) on May 06, 2009 at 10:01 UTC

    In fact I do like you have written. Posted code is simplified. But the problem was not in populating hash but in printing out some values. Anyway I have found solution and feel great!

      In general, on this forum I think you will find that simplifying code in that way (e.g. converting references into hashes or arrays) will only confuse us and make us do extra work (like the code BrowserUK posted). This is especially true when there are performance or memory issues. There are plenty of people here who are quite comfortable with complex data structures.

      Best, beth