I don't understand your code.
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
}
}
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.
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.)