in reply to Re^3: Accessing Large Else-If Condition in a Separate Files
in thread Accessing Large Else-If Condition in a Separate Files
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:
use strict; use warnings; my %data; # Replace this with real code to generate %data. %data = ( foo1 => [ '1 - 201 - 229', '2 - 201 - 229', '3 - 201 - 229', ], foo2 => [ '1 - 201 - 218', '2 - 201 - 218', '3 - 201 - 218', '4 - 201 - 218', '5 - 201 - 218', '6 - 201 - 218', '7 - 201 - 218', ], ); use File::Slurp; use Data::Dumper; $Data::Dumper::Useqq = 1; write_file( 'big_decision_hashref.dat', Dumper(\%data) ) ; #use YAML::Syck; $YAML::Syck::ImplicitTyping = 1; #DumpFile( 'big_decision_hashref.yml', \%data );
use strict; use warnings; use Data::Dumper; $Data::Dumper::Useqq = 1; my $data_href = do 'big_decision_hashref.dat'; #use YAML::Syck; $YAML::Syck::ImplicitTyping = 1; #my $data_href = LoadFile( 'big_decision_hashref.yml' ); die unless $data_href; my $dataset = $ARGV[0] || 'foo1'; my $act_bsites_aref = $data_href->{$dataset} or die "Invalid dataset '$dataset'"; my @act_bsites = @{ $act_bsites_aref }; #print Dumper \@act_bsites; # For debugging
|
|---|