in reply to Re^2: Alternate for "open"
in thread Alternate for "open"

You've now been given several suggestions:

Which of these have you done?

In particular, does your code contain use strict; and use warnings;?

It's not an completely unreasonable idea to try to measure the memory footprint of your hash, but most monks here would not do that to find the problem. Better to simplify your code so you can identify the problem.

Just remove everything until it runs properly, then start adding stuff back in. If it is a really large and ugly codebase, take the opportunity to refactor and move code out into modules. This is better practise for many reasons and will help you do this kind of debugging by making it easy to use and not use parts of the code.

You could also:

There, now you have a bunch more suggestions. It will be nice to hear back from you when you've tried some of them and you are still stuck.

The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^4: Alternate for "open"
by ravi45722 (Pilgrim) on Nov 17, 2015 at 08:29 UTC

    While I posted my first program here "MONKS" suggested to use strict. From that time I never miss those two lines in my code. And I am very sure that I am using while to read the file (Already posted).

    As per your suggetion I am trying to run the code piece by piece now. And my first piece is reading CDR & build the values in hash. So, I want to be sure that my hash is not taking much memory.

    Thanks for suggestions

      The only sample you post:

      $cmp=substr(reverse($line),0,1); if ($cmp eq ";") {

      doesn't look like it has strict and warnings switched on. Or if it is, you're reusing $cmp which isn't necessary and recycling vars means you're probably not scoping correctly. That's why you get it as a suggestion again - because we have no evidence to the contrary.

        I updated the post as they suggested and posted my output.

      I don't believe you - if you have use strict; use warnings when you also have:

      my $total_size = total_size(\%val); print "\%val :",$total_size,$/; my $total_size = total_size(\%seen_cdr);

      Your code is generating errors: "my" variable $total_size masks earlier declaration in same scope.

      Either you don't have these switched on, or you've code that's generating errors every time it runs, and you're asking for someone to fix it for you.