SpellsT: @_WizardSchool school | @_WizardSchool sphere #### Aura: visible &_color | @_Emotion | @_Align Resist: immune | is &_roll:1d100 % magic resistant | has no resistance #### my %game_data; open( IN, "<", "game_data.txt" ) or die "game_data.txt: $!"; while () { chomp; my ( $key, @values ) = split( /\s*[:|]\s*/ ); $game_data{$key} = [ @values ]; } close IN; my %init_func = { color = sub { my $val=some_simple_op(); return $val}, roll = \&roll, ... } for my $key ( keys %game_data ) { my @replace_vals = (); for my $val ( @{$game_data{$key}} ) { if ( $val =~ /[@&]_\S+/ ) { # need to split and process my @words = split ' ', $val; $val = ''; for my $wrd ( @wrds ) { if ( $wrd =~ /\@_(\S+)/ ) { my $refkey = $1; if ( exists( $game_data{$refkey} )) { my $n = @{$game_data{$refkey}}; $wrd = $game_data{$refkey}[rand $n]; } else { warn "No $refkey in game_data for $key\n"; } } elsif ( $wrd =~ /\&_(\S+)/ ) { my ( $refkey, @args ) = split /[:,]/, $1; if ( exists( $init_func{$refkey} )) { $wrd = $init_func{$refkey}->(@args); } else { warn "No $refkey function for $key\n"; } } $val .= "$wrd "; } } push @replace_vals, $val; } $game_data{$key} = [ @replace_vals ]; }