In order to describe it more clearly , i have 1 example below, in which i have created 1 big hash-of-hash. Although i have put only 2 HOH inside %TV overhere ( just for clarity sake ), but in my code i have it 300 or more HOH ( while incrementing the key e.g jetsons1, jetsons2... ) in order to check the memory usage.
#!/usr/bin/perl5.8
use Proc::ProcessTable;
#use Tie::File::AsHash;
my %hash= ();
%TV = ( flintstones =>{ series => "flintstones",
nights => [ qw(monday thursday friday) ],
members => [ { name => "fred", role => "
+lead", age => 36, },
{ name => "wilma", role => "
+wife", age => 31, },
{ name => "pebbles", role => "
+kid", age => 4, },
],
},
jetsons1 => { series => "jetsons",
nights => [ qw(wednesday saturday) ],
members => [ { name => "george", role => "l
+ead", age => 41, },
{ name => "jane", role => "w
+ife", age => 39, },
{ name => "elroy", role => "k
+id", age => 9, },
]
},
sub memory_use {
my $t = new Proc::ProcessTable;
foreach my $got ( @{$t->table} ) {
next if not $got->pid eq $$;
return $got->size;
}
}
my $count = 10;
my $key = 'test';
#tie %hash, 'Tie::File::AsHash', 'abc.csv', split => ':' or die "Pr
+oblem tying %hash: $!";
foreach my $family (keys %TV) {
$count++;
my $record = "";
my $rec = $TV{$family};
my $key = $family . $rec->{series};
for $person ( @{ $rec->{members} } ) {
$record .= $person->{name}."," . $person->{role}. ","
. $person->{age} . ","
. $rec->{series} . ","
. $rec->{nights}[0];
}
print "\n Key: $key \n";
print "\n Record: $record \n";
$hash{$key} = $record;
if ( $count%10 == 0 ) {
sleep(10 );
print "\n Record counter => [$count] \n";
print "\n Process Status:" . ( ( memory_use()/1024 )/1024 )
+."MB \n";
%hash = (); # if we comment it memory constant
}
} #----for 1----#
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.