pip9ball has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I have a question reqarding Randal's nifty "safe undumping" article found here: http://www.stonehenge.com/merlyn/LinuxMag/col29.html

On line 17, code is inserted to clear out the contents of %TABLE, parse a string, then return a hash reference to the %TABLE.

file: { %TABLE = (); } assignment(s?) /\z/ { \%TABLE }
Is it possible to instead of clear out the contents of %TABLE, append new elements to %TABLE?

I have some input data very similar to perl with comments in between. I want to be able to send a single assignment to the parser one at time to build the final %TABLE incrementally.

Thanks and Regards,

-P

Replies are listed 'Best First'.
Re: Safe undumping
by ikegami (Patriarch) on Nov 10, 2004 at 21:15 UTC

    Simply remove { %TABLE = (); } from line 17. $parser->file(...) will reuse entries already encountered in past calls to $parser->file(...).

    If you want to option to clear the table, add the following rule to the grammar:
    clear_table: { %TABLE = (); }
    and do
    $parser->clear_table('')
    to clear it.
    $parser->clear_table()
    may also work, but may cause warnings under use strict.

    (Untested, since the program in the linked article doesn't run on my system. I guess my dumper gives something different than his.)

      Excellent! Thanks!

      -P