Which perl version are you using, which OS?
I don't see a specific problem with the code. It should have a
use strict; at the beginning, though.
How long is a typical JSON string?
Can you create a sample input that will show memory increase? For example, instead of reading in the file, just loop over the same line a couple of 1000 times and watch memory consumption.
The problem the others are mentioning doesn't look like a problem to me since $jp falls out of scope after every loop iteration.
Memory stays the same for me if I run this 500,000 times on an example line.
edit: specifically, how many array elements does a typical structure have? my assumption was that you have many lines, but maybe your lines/JSON strings are very big?
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.