in reply to Undesired array growth

It sure is unclear what you're trying to do here, and I have to believe there's got to be a better way to do it.

But I've identified a bug which may be responsible at least in part for whatever problem you're seeing. You're missing a backwhack in front of the array in the third call to del(), at line 25 of the posted code. That is,

del(@{$meta[$page+1]},0);
should be
del(\@{$meta[$page+1]},0);
Of course, it could really be simply
shift @{$meta[$page+1]};
Couldn't it? Otherwise, it looks like your sub del is attempting to re-implement the splice built-in function.

Good luck!

Between the mind which plans and the hands which build, there must be a mediator... and this mediator must be the heart.

Replies are listed 'Best First'.
Re^2: Undesired array growth
by jwkrahn (Abbot) on Jan 09, 2009 at 03:11 UTC
    should be
    del(\@{$meta[$page+1]},0);

    $meta[$page+1] already contains an array reference so it should be:

    del($meta[$page+1],0);
      Good point, thanks. Updated those, but the problem is still occurring. =/
      Good catch. And the same is true for the other two calls to del() as well.
Re^2: Undesired array growth
by apok (Acolyte) on Jan 09, 2009 at 04:06 UTC

    Good catch on the backwhack, thanks! Fixed that typo, but the problem is still continuing. =/ I'd love to find a simpler way to do it, but this is the best way I could come up. Granted, I do have a tendency to over-complicate things.

    So at this point in the script, the data is stored in a 3d array. @meta holds the pages, each page holds an array of lines, and each line points to an array of 3 values: Field Name, Field Type, and Field Details. Since it is originally raw text pulled from a pdf, each line is not necessarily a field's full information. Some field names are long enough to be split into two lines, and some of the field details can take up to 15 or 20 lines, but the field type is always only one line.

    The script uses that to check if the line below the current one is the beginning of another field definition (field 0,1,2 defined) or a continuation of the current one (1 undefined, either/both 0/2 defined). If the latter it concats the lower line values onto the current line ($line_num) and then removes the lower line($line_num+1).

    I tried using splice and undef, but that just leaves $line_num+1 undefined. I was hoping to get around that with sub del, so it could just concat and loop until a new definition (0,1,2 defined) was next, and then move down and repeat. It works great... until the end when the array of lines on the page starts growing.