http://www.perlmonks.org?node_id=1231516


in reply to making a markovian "mad lib"

I'll have a go

for (@{$data}) { my $key = $_->[0]; my $last_element = $#{$_}; my $random = $_->[rand($#{$_}) + 1]; $vars{$key} = $random; }
A more concise way:
%vars = map { $_->[0],$_->[rand($#{$_}) + 1] } @{$data};
You could represent like:
$story = { protaganist => [ 'al debaran','narrator','japh','gilligan' ], dog => [ 'my pretty pitty' ], };
or
data/protaganist.txt al debaran the narrator japh data/trials.txt adventures bedraengisse