in reply to Memory utilization and hashes
Also, I don't understand what's going on when you have two queries or two answers in a row, as in your data example.while (<>) { $l = $_; chomp $; # you probably want to +chomp $l, or possibly $_ (but you no longer use $_), but not $ @vals = split /;/, $l; # you split your line i +nto @vals, but no longer use that variable. Besides, # declaring @vals with +my would be good practice if ($l =~ /Query/) { # you could use somethi +ng like: if $vals[0] eq "Query" %pairs{$l[1]}{$l[2]} = $l[3]; # where are $l[1], $l[2 +] and $l[3] coming from? Also, %pairs{...} is probably a syntax error +. } elsif {$l =~ /Answer/) { # again, you could use: + if $vals[0] eq "Answer". Also, "elsif {..." is a syntax error. %pairs{$l[1}{$l[2]} = $l[3]; # again, where are $l[1 +], $l[2] and $l[3] coming from? Also a syntax error. $json = encode_json $pairs{$l[1]}; # given the previous co +de, I doubt that you really want to encode $pairs{$l[1]} print $json."\n"; # is you intent to prin +t to the screen? delete $pairs{$l[1]}; # not sure it's needed, + since you just reuse the same variable in the next iteration } }
With the code you're showing, the hash should not grow significantly, even without the call to delete. (Update:: but this is no longer true with the updated code posted below.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Memory utilization and hashes
by bfdi533 (Friar) on Jan 17, 2018 at 21:32 UTC | |
by Laurent_R (Canon) on Jan 17, 2018 at 21:49 UTC | |
by Laurent_R (Canon) on Jan 17, 2018 at 22:11 UTC | |
by bfdi533 (Friar) on Jan 17, 2018 at 22:35 UTC | |
by Laurent_R (Canon) on Jan 17, 2018 at 23:48 UTC | |
by Laurent_R (Canon) on Jan 17, 2018 at 21:39 UTC |