FFRANK has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

1- Is there a way during a while (<IN>), to first initialize everything (all variables, arrays, subs, etc.) in a single command (just curious).

2- Is there a way during a process to track/monitor exactly what (variable, array, hash) gets how much memory allocated.

Thanks very much

UPDATE: given the amount of data, %seen eating memory.

#!/usr/bin/perl -w use strict; use Algorithm::Loops qw(NestedLoops); sub combo { #thanks Roy Johnson my $something = shift; my %seen; my $combos = NestedLoops([$something->[0],map {my $_hold = $_; sub {[grep {!$seen{join(':', sort @_, $_)}++} @{$something->[$_hol +d]}]}} 1..$#$something]); my $value = 0; my ($result, $someFct); while (my @result = $combos->()) { if (someSub(\@result) > $value) { $result = join (',', @result); $someFct = (someSub(\@result)); } else {();} } return $someFct,"\t",$result,"\n"; }

Replies are listed 'Best First'.
Re: Memory monitoring
by Fletch (Bishop) on Jul 03, 2007 at 17:07 UTC

    Providing your variables are properly scoped to the smallest possible enclosing scope with my you shouldn't have any "memory leaks". At most you should hit a maximum size (dependent on the largest size of what you're pulling out of the row) and stick around there (or slowly grow if you're remembering stuff from line to line). Depending on the platform you could use system tools like top or ps to watch the process as a whole, or a module like Devel::Size to see how big your Perl data structures are getting.

    Show some actual code and you might get more helpful responses than my generalities.

Re: Memory monitoring
by educated_foo (Vicar) on Jul 03, 2007 at 17:09 UTC
    I would try Devel::Size for (2). I'm not sure what you mean for (1).
      In (1), I meant: to initialize everything at the beginning, some "everything" =(); initializer.
        No, there's no such way.
        while (...) { # these all initialized with undefined value my($you, $have, $to, $declare, $your, $variables, $one_by_one, $just +_like_this); }
        But, it's still not clear about what do you want to achieve by that. You can also use hash, and intialize all elements with empty or zero values.
        my %hash = map { $_ => '' } qw(list of elements you want to initialize);

        Open source softwares? Share and enjoy. Make profit from them if you can. Yet, share and enjoy!