in reply to Re: Interpolation of variables read from a file
in thread Interpolation of variables read from a file
But I find a "bad" way to make it, and I think this way is more efficient in mem and time :-(
File: main.pl => the main source fileFile: template.plrequire "all_hashes.pl"; # read in all the hashes our $item = "Perl"; # this $item must be global :-( require "template.pl"; # perl interpolates all the variable print $out; # $out is defined in template.pl #...
File: all_hashes.pl => the file contains all the hashesmy $out = "-p $act1{$item} -p $act2{$item} ...";
It's bad, hardcoded and has many global variables, however, a simple and fast way :-(my %act1 = ( "food" => "eat it", "drink" => "drink it", "Perl" => "play it"); my %act2 = ( "food" => "prepare it", "drink" => "be drunk", "Perl" => "write it"); #...
|
|---|