in reply to Accessing Large Else-If Condition in a Separate Files

In answer to the Update:

so chuck the whole current file into the __DATA__ section and:

local $/ = 'if ('; while (<DATA>) { chomp; next if ! length; next unless /eq '(\w+)'/; my $site = $1; push @{$site_data{$site}}, /'(\d+[^']+)'/gm; }

to parse it.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Accessing Large Else-If Condition in a Separate Files
by moritz (Cardinal) on Jun 05, 2007 at 09:35 UTC
    Why do something on your own if CPAN can do the same for you?

    Just store the Hash of Arrays in a serialized format (such as YAML, JSON, XML or even use Data::Dumper to write to a perl file) and you don't have to worry about parsing and writing theses lines by yourself

      Hi,
      That's interesting. Can you give example how this can be done with one of those modules?

      ---
      neversaint and everlastingly indebted.......

        Zaxo's update clearly illustrates moritz's point. Because it is *definitely* the way I would approach the problem, and I would hate for you to overlook this solution, I will provide a more explicit example.

        In the code below, you can switch from Data::Dumper to YAML by changing which lines are commented out.

        Program1, which generates and stores the decision hash:

        Program2, which loads and uses the decision hash: